rails 3 i18n set locale does not work
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
conf开发者_如何学运维ig.i18n.locale = :de
but I18n.locale is still :en after this. any ideas?
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.
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
精彩评论