forked from OpenNeo/impress
infer locale from params, then cookies, then Accept-Language header
This commit is contained in:
parent
3b1ffe71a9
commit
d96c54f3cc
5 changed files with 20 additions and 6 deletions
2
Gemfile
2
Gemfile
|
@ -48,6 +48,8 @@ gem "carrierwave", "~> 0.5.8"
|
|||
|
||||
gem "parallel", "~> 0.5.17"
|
||||
|
||||
gem "http_accept_language", :git => "git://github.com/iain/http_accept_language.git"
|
||||
|
||||
group :development do
|
||||
gem "bullet", "~> 4.1.5"
|
||||
end
|
||||
|
|
|
@ -4,6 +4,12 @@ GIT
|
|||
specs:
|
||||
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
|
||||
remote: git://github.com/igrigorik/em-http-request.git
|
||||
revision: ce50f322ce08d43a4a747cf333ea576765d764c4
|
||||
|
@ -254,6 +260,7 @@ DEPENDENCIES
|
|||
fog (~> 1.1.2)
|
||||
haml (~> 3.0.18)
|
||||
hoptoad_notifier
|
||||
http_accept_language!
|
||||
jammit (~> 0.5.3)
|
||||
memcache-client (~> 1.8.5)
|
||||
mini_magick (~> 3.4)
|
||||
|
|
|
@ -19,11 +19,12 @@ class ApplicationController < ActionController::Base
|
|||
true
|
||||
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
|
||||
inference = params[:locale]
|
||||
inference if inference && I18n.available_locales.include?(inference.to_sym)
|
||||
return params[:locale] if valid_locale?(params[:locale])
|
||||
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
|
||||
|
||||
def localized_fragment_exist?(key)
|
||||
|
@ -54,5 +55,9 @@ class ApplicationController < ActionController::Base
|
|||
def user_is?(user)
|
||||
user_signed_in? && user == current_user
|
||||
end
|
||||
|
||||
def valid_locale?(locale)
|
||||
locale && I18n.available_locales.include?(locale.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
en-meep:
|
||||
en-MEEP:
|
||||
app_name: Dreep to Impreep
|
||||
organization_name: OpenMeep
|
||||
your_items: Your Meeps
|
|
@ -1,4 +1,4 @@
|
|||
en-meep:
|
||||
en-MEEP:
|
||||
will_paginate:
|
||||
previous_label: "← Preevious"
|
||||
next_label: "Neext →"
|
Loading…
Reference in a new issue