Fallbacks

svenfuchs edited this page Sep 13, 2010 · 1 revision

We store static translation data in Rails in en-US. How can we make sure things don’t need to be duplicated for all the en variations like en-GB, en-CA etc.?

One solution could be to define a virtual root locale which would equal to en-US.

Then for en-GB we’d have a fallback route like:


  en-GB » en » root (en-US)

This also should work for en-US itself:

  en-US » en

… as everything defined in en-US would already be found in the original locale root could be omitted in this case.

So, the algorithm could be:


fallbacks = locale.parents << root

… with locale.parents returning an array of the locale itself and all parents of the locale.