17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/homura/set_locale.rb', line 17
def set_locale
if (param_locale = params['locale']) && locale_available?(param_locale)
cookies.permanent['locale'] = param_locale
I18n.locale = param_locale and return
end
if (cookie_locale = cookies['locale']) && locale_available?(cookie_locale)
I18n.locale = cookie_locale and return
end
http_accept_language = request.['HTTP_ACCEPT_LANGUAGE'] || ''
preferred_locales = http_accept_language.split(',').map { |l|
l.split(';').first.downcase.gsub(/-[a-z0-9]+$/i) { |x| x.upcase }
}
I18n.locale = preferred_locales.find { |l|
locale_available?(l)
}
end
|