firstruby

Master ruby with us

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

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: