I'm surprised to see that Ruby on Rails' i18n doesn't properly support locales such as en-GB, en-US, en-AU, etc. Looking around it seems the task is left to third party libraries and code. I searched around and I found rails-i18n-translation-inheritance-helper but it doesn't seem that active. Is nobody localizing their Rails apps or is there another solution that I'm missing?
Asked
Active
Viewed 1,384 times
1 Answers
9
You can set your current locale to anything you want using something like
I18n.locale = 'en_US'
To avoid repeating most of the stuff for similar locales, you can then setup proper fallbacks in the i18n initializer like so:
config.i18n.default_locale = 'en'
config.i18n.fallbacks = {
'en_US' => 'en',
'en_GB' => 'en',
'de_DE' => 'de',
'de' => 'en'
}
Now you only need to create all your different localization files as fortunately, everything is part of the default i18n gem.

Holger Just
- 52,918
- 14
- 115
- 123
-
Ah... I didn't know about config.i18n.fallbacks. I'll give it a try. – Pablo Fernandez Mar 26 '12 at 06:19
-
Notes: (1) Territory fallbacks are automatic ("en-US" to "en") in Rails for some time now. (2) It should be "en-US" with a dash not "en_US" with an underscore (See: https://stackoverflow.com/questions/4904803/en-us-or-en-us-which-one-should-you-use) – Christopher Oezbek Mar 18 '21 at 08:49