Reputation: 392
i would like translations to fallback to :en, but the default locale is :de. how can i achieve this best? i tried in 'config/application.rb'
config.i18n.default_locale = :en
config.i18n.locale = :de
but I18n.locale is still :en after this. any ideas?
Upvotes: 1
Views: 4310
Reputation: 145
If you set locale like the following line
I18n.locale = :de
Then after the line triggered, EVERY visitor will using de
locale, not the default locale en
.
So the better way is
In your application_controller.rb
before_filter: set_locale
private
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
Reply to Jonathan Clark:
Every controller inherited from application_controller will set the locale.
Upvotes: 3
Reputation: 9771
You cant set the locale in your environments.
you have to put default_locale in your environment config file and you have to set your locale in your application itself.
For example in your application_controller.rb
before_filter: set_locale
private
def set_locale
I18n.locale = params[:locale] if params[:locale]
end
Upvotes: 1