danijel
danijel

Reputation: 576

How to setup locales for Rails 4

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:

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

Upvotes: 0

Views: 666

Answers (2)

danijel
danijel

Reputation: 576

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]

Upvotes: 1

Maksim Gladkov
Maksim Gladkov

Reputation: 3079

You can add the code below:

class ApplicationController
    ...

    before_filter :set_locale

    ...

    private

    def set_locale
        I18n.locale = :hr
    end 

end 

Upvotes: 0

Related Questions