fixes locales issue
This commit is contained in:
parent
c2c1961bd0
commit
47405b5b19
1 changed files with 28 additions and 29 deletions
|
@ -8,43 +8,42 @@ module Foodsoft
|
||||||
before_filter :set_locale
|
before_filter :set_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def explicitly_requested_language
|
||||||
def explicitly_requested_language
|
params[:locale]
|
||||||
params[:locale]
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def session_language
|
def session_language
|
||||||
session[:locale]
|
session[:locale]
|
||||||
end
|
end
|
||||||
|
|
||||||
def browser_language
|
def browser_language
|
||||||
request.env['HTTP_ACCEPT_LANGUAGE'] ? request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first : nil
|
request.env['HTTP_ACCEPT_LANGUAGE'] ? request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_language
|
def default_language
|
||||||
::I18n.default_locale
|
::I18n.default_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def select_language_according_to_priority
|
def select_language_according_to_priority
|
||||||
explicitly_requested_language || session_language || browser_language
|
language = explicitly_requested_language || session_language || browser_language
|
||||||
end
|
language.to_sym unless language.blank?
|
||||||
|
end
|
||||||
|
|
||||||
def available_locales
|
def available_locales
|
||||||
::I18n.available_locales
|
::I18n.available_locales
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_locale
|
def set_locale
|
||||||
if available_locales.include?(select_language_according_to_priority)
|
if available_locales.include?(select_language_according_to_priority)
|
||||||
::I18n.locale = select_language_according_to_priority
|
::I18n.locale = select_language_according_to_priority
|
||||||
else
|
else
|
||||||
::I18n.locale = default_language
|
::I18n.locale = default_language
|
||||||
end
|
|
||||||
|
|
||||||
locale = session[:locale] = ::I18n.locale
|
|
||||||
logger.info("Set locale to #{locale}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
locale = session[:locale] = ::I18n.locale
|
||||||
|
logger.info("Set locale to #{locale}")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue