localization - Rails i18n different locales for front-end, back-end -
i trying developer commerce solution back-end , front-end sides. finished back-end separated namespaces , realized need separate different locales every side. there solution how set locale front-end , back-end separately? advices
http://guides.rubyonrails.org/i18n.html#setting-and-passing-a-locale
the locale can either set pseudo-globally
i18n.locale
(which usesthread.current
like, e.g.,time.zone
) or can passed option#translate
,#localize
.if no locale passed,
i18n.locale
used:
i18n.locale = :de i18n.t :foo i18n.l time.now
explicitly passing locale:
i18n.t :foo, locale: :de i18n.l time.now, locale: :de
the
i18n.locale
defaultsi18n.default_locale
defaults:en
. default locale can set this:i18n.default_locale = :de
so, example 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
Comments
Post a Comment