8

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.

Anrothan
  • 490
  • 5
  • 11

3 Answers3

25

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.

Mkou
  • 515
  • 4
  • 12
0

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.

Anrothan
  • 490
  • 5
  • 11
0

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

Pavel Chuchuva
  • 21,289
  • 9
  • 93
  • 110