Reputation: 37
I am trying to developer commerce solution with back-end and front-end sides. I just finished back-end which is separated by namespaces and realized that i need to separate different locales for every side. So is there a solution how to set locale for front-end and back-end separately? Thanks for advices
Upvotes: 2
Views: 1006
Reputation: 321
http://guides.rubyonrails.org/i18n.html#setting-and-passing-a-locale
The locale can be either set pseudo-globally to
I18n.locale
(which usesThread.current
like, e.g.,Time.zone
) or can be passed as an option to#translate
and#localize
.If no locale is passed,
I18n.locale
is used:
I18n.locale = :de
I18n.t :foo
I18n.l Time.now
Explicitly passing a locale:
I18n.t :foo, locale: :de
I18n.l Time.now, locale: :de
The
I18n.locale
defaults toI18n.default_locale
which defaults to:en
. The default locale can be set like this:I18n.default_locale = :de
So, example from real life (locale, based on Accept-Language HTTP-header (https://github.com/iain/http_accept_language) ):
class ApplicationController < ActionController::Base
#...
before_filter :set_locale
def set_locale
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
end
end
Upvotes: 1