Rails does not permit changing locale

I'm trying to change the locale that my rails (4.1.4) application is using, but every time I try to change it in the console using commands such as

I18n.locale = :es
I18n.default_locale = :de

an I18n::InvalidLocale error is brought up. This is the case for every locale I test, including regional ones such as :en-US. This is true even if I have a *.yml file set up for that locale. The only one that works is :en, which is the default for me.

I feel like this should be something pretty basic as all the resources I find seem to skip past this as a given, but it's not working for me and I can't figure out where to look for the problem source.


Did you add the new locale in application.rb ?

config.i18n.enforce_available_locales = false
config.i18n.available_locales = [:en, :es, :de]
config.i18n.default_locale = :de

You also have to create the files en.yml , es.yml and de.yml in your config/locale folder.

Thanks! When I looked in that file, I realized that in addition to the answer you gave, Rails provides it's own solution commented out -

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]

So basically it takes a translation file such as pt-br.yml and adds that to the list of valid locales.

Make sure you have added es.yml and de.yml to the config/locales folder.

Need Your Help

SSRS 2005 -Set Visibility based on dataset rowcount

reportingservices-2005 visibility reporting-services

I have a line and a table in my report that I want to hide if my dataset has no rows in it.

iOS: helpfulness of didReceiveMemoryWarning:

ios cocoa-touch memory-management

I'm at the part of my development process for tracking down crashing and memory leaks. As a strategy, do you put any NSLog messages or notifications of some such into didReceiveMemoryWarning:? The