Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper way to handle geographic locales in Ruby on Rails?

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?

like image 562
pupeno Avatar asked Mar 25 '12 10:03

pupeno


1 Answers

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.

like image 176
Holger Just Avatar answered Sep 28 '22 09:09

Holger Just