Skip to content

Commit

Permalink
Merge pull request #54 from cryptape/accept-language
Browse files Browse the repository at this point in the history
Set locale by Accept-Language header
  • Loading branch information
ashchan authored Dec 6, 2018
2 parents 5e15de4 + 4cab83d commit d9ffe32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ gem 'maxminddb', '~> 0.1.22'
gem 'globalize', '~> 5.2'
gem 'globalize-accessors', '~> 0.2.1'

gem 'http_accept_language', '~> 2.1', '>= 2.1.1'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ GEM
globalize (~> 5.0, >= 5.0.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http_accept_language (2.1.1)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
Expand Down Expand Up @@ -283,6 +284,7 @@ DEPENDENCIES
dotenv-rails
globalize (~> 5.2)
globalize-accessors (~> 0.2.1)
http_accept_language (~> 2.1, >= 2.1.1)
jbuilder (~> 2.5)
kaminari
listen (>= 3.0.5, < 3.2)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ class ApplicationController < ActionController::Base
before_action :set_locale

def set_locale
locale = params[:locale]&.to_sym || I18n.default_locale
locale = I18n.default_locale unless I18n.available_locales.include?(locale)
I18n.locale = locale
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
end

end

0 comments on commit d9ffe32

Please sign in to comment.