I'm developing a rails 4 application with i18n support. I've installed i18n gem. In my application.rb file I have this code
config.i18n.enforce_available_locales = true
config.i18n.available_locales = [:es]
config.i18n.default_locale = :es
In development mode all works flawlessly, but when I switch to production everything outputs "translation missing". I tried different solutions such as write this code in config/initializers/locale.rb
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
I18n.default_locale = :es
And also write this in config/environment.rb
I18n.reload!
Nothing worked. Going to console mode shows this, the same as when I open the app in web browser.
user@opendraft:/home/user/www/awesomeapp# RAILS_ENV=development bundle exec rails c
Loading development environment (Rails 4.0.1)
irb(main):001:0> I18n.t('btn_login')
=> "Acceder"
irb(main):002:0> exit
user@opendraft:/home/user/www/awesomeapp# RAILS_ENV=production bundle exec rails c
Loading production environment (Rails 4.0.1)
irb(main):001:0> I18n.t('btn_login')
=> "translation missing: es.btn_login"
irb(main):002:0> exit
My config/locales/es.yml file:
es:
btn_login: "Acceder"
reset: "Reinicializar"
login: "Acceso"
sign_up_candidate: "Candidatos"
sign_up_company: "Empresas"
sign_up_teacher: "Profesores"
All translations from config/locales/*
are auto loaded, according to comments included on application.rb
.
I have some apps using only :es
as locale, and the only configuration in application.rb
is:
config.i18n.default_locale = :es
Nothing else.
Edit
Checking my app, I can see that
config.i18n.available_locales = [:es]
is necessary if you want to remove any reference to :en
locale. You can check it with this:
I18n.locale_available?(:en) # => false
FYI, In a Rails 3 app using only :es
as locale, I have this line too:
I18n.config.enforce_available_locales = false
Simply to avoid the deprecation warning:
[deprecated] I18n.enforce_available_locales will default to true in the future.
If you really want to skip validation of your locale you can set
I18n.enforce_available_locales = false to avoid this message.