firstruby

Master ruby with us

Archive for May, 2011

Language fallback mechanism in Ruby on Rails

Posted by firstruby on May 29, 2011

Language fallback mechanism in Ruby on Rails is very useful. It is useful in 2 ways,

1) File missing : If particular locale file say German locale ‘de’ is set from browser, then Rails application will look for de.yml file in /config/locales folder, and if de.yml is missing, then by default language fallback mechanism will load en.yml file as default.

2) Entry missing: If German locale ‘de’ is set from browser, then Rails application will look for de.yml file in /config/locales folder. In case, particular entry is missing in de.yml file, then conversion for the same language will be loaded from en.yml file.

To achieve this, just need to install latest I18n gem and need to create file /config/initializers/i18n.rb file with following,

I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

Reference URL : http://stackoverflow.com/questions/2324398/fall-back-to-default-language-if-translation-missing

Posted in Useful Links | Tagged: , , , | Leave a Comment »