I am working on a rails app (3.2.13) that is being translated into several languages, including (one of the 3 available flavours of) Norwegian. On public pages, the app uses the browser's language settings to set locale.
Most browsers offer 3 separate Norwegian shortcodes: no
, nb
& nn
. The translations we have are in nb
, but I think it would be best if no
& nn
also defaulted to nb
. That way, if a user's browser language preferences were set to no
then en
, the app would try to supply nb
Norwegian first, instead of skipping straight to English.
Is it possible to configure a list of "language aliases" for the i18n gem, something like this?
config.i18n.available_locales = [:sv, :en, :nb, :da, :fi]
config.i18n.aliased_locales = [:nb <= :no, :nb <= :nn]
Short answer
Take a look to the fallbacks
Create a file in
initializers
likei18n_fallbacks.rb
Here the reference
Things related
You can even set multiple fallbacks, and they will be taken in the same order as specified:
for instance:
de.yml
en.yml
es.yml
You get the following:
In latest i18n gem (0.7.0) I have found it necessary to define fallback locales like this (in
config/application.rb
):You also need to set
config.i18n.fallbacks = true
in allconfig/environments/*.rb
files.