Question

i have a rather specific setup regarding rails internationalization. I'm using rails-i18n gem, but that shouldn't matter. It worked perfectly with Rails 3. Here is my config from config/application.rb

config.i18n.default_locale = :en
config.i18n.locale = :hr

Let me explain:

  • locale is set to :hr (Croatian) because I mostly make localized applications in Croatian language
  • default locale is set to :en because I'm often using gems like rails-admin which have English translations included. It plays nicely in production where missing (Croatian) translations fallback to English. That's fine, all admins understand English :)

And the question is: how to make it work with Rails 4?

It seems that Rails 4 ignores config.i18n.locale, and it always use :en locale.

So far, I've been using before_action to set I18n.locale = :hr but that doesn't work in Rails console or Rack middleware...

Thanks in advance,

Danijel

Was it helpful?

Solution

I found a simple solution and I'm posting it here...

Insert into config/application.rb

  config.i18n.default_locale = :hr
  config.i18n.available_locales = [:hr, :en]
  config.i18n.fallbacks = [:en]

Remove or comment the following line from config/environments/production.rb

  # config.i18n.fallbacks = true

or change it to:

  config.i18n.fallbacks = [:en]

OTHER TIPS

You can add the code below:

class ApplicationController
    ...

    before_filter :set_locale

    ...

    private

    def set_locale
        I18n.locale = :hr
    end 

end 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top