1
0
Fork 0
forked from OpenNeo/impress

infer locale from params, then cookies, then Accept-Language header

This commit is contained in:
Emi Matchu 2013-01-11 11:07:11 -06:00
parent f63e4ecc43
commit 420c52d296
5 changed files with 20 additions and 6 deletions

View file

@ -48,6 +48,8 @@ gem "carrierwave", "~> 0.5.8"
gem "parallel", "~> 0.5.17" gem "parallel", "~> 0.5.17"
gem "http_accept_language", :git => "git://github.com/iain/http_accept_language.git"
group :development do group :development do
gem "bullet", "~> 4.1.5" gem "bullet", "~> 4.1.5"
end end

View file

@ -4,6 +4,12 @@ GIT
specs: specs:
eventmachine (1.0.0.beta.4) eventmachine (1.0.0.beta.4)
GIT
remote: git://github.com/iain/http_accept_language.git
revision: 7738e45ba154015597fca749b7d0257861c14a02
specs:
http_accept_language (2.0.0.pre)
GIT GIT
remote: git://github.com/igrigorik/em-http-request.git remote: git://github.com/igrigorik/em-http-request.git
revision: ce50f322ce08d43a4a747cf333ea576765d764c4 revision: ce50f322ce08d43a4a747cf333ea576765d764c4
@ -254,6 +260,7 @@ DEPENDENCIES
fog (~> 1.1.2) fog (~> 1.1.2)
haml (~> 3.0.18) haml (~> 3.0.18)
hoptoad_notifier hoptoad_notifier
http_accept_language!
jammit (~> 0.5.3) jammit (~> 0.5.3)
memcache-client (~> 1.8.5) memcache-client (~> 1.8.5)
mini_magick (~> 3.4) mini_magick (~> 3.4)

View file

@ -19,11 +19,12 @@ class ApplicationController < ActionController::Base
true true
end end
# This locale-inferrence method is designed for debugging. Once we're ready
# for production, we'll probably start inferring from domain.
def infer_locale def infer_locale
inference = params[:locale] return params[:locale] if valid_locale?(params[:locale])
inference if inference && I18n.available_locales.include?(inference.to_sym) return cookies[:locale] if valid_locale?(cookies[:locale])
Rails.logger.debug "Preferred languages: #{http_accept_language.user_preferred_languages}"
http_accept_language.language_region_compatible_from(I18n.available_locales.map(&:to_s)) ||
I18n.default_locale
end end
def localized_fragment_exist?(key) def localized_fragment_exist?(key)
@ -54,5 +55,9 @@ class ApplicationController < ActionController::Base
def user_is?(user) def user_is?(user)
user_signed_in? && user == current_user user_signed_in? && user == current_user
end end
def valid_locale?(locale)
locale && I18n.available_locales.include?(locale.to_sym)
end
end end

View file

@ -1,4 +1,4 @@
en-meep: en-MEEP:
app_name: Dreep to Impreep app_name: Dreep to Impreep
organization_name: OpenMeep organization_name: OpenMeep
your_items: Your Meeps your_items: Your Meeps

View file

@ -1,4 +1,4 @@
en-meep: en-MEEP:
will_paginate: will_paginate:
previous_label: "&#8592; Preevious" previous_label: "&#8592; Preevious"
next_label: "Neext &#8594;" next_label: "Neext &#8594;"