gearheads
/
mastodon
Archived
2
0
Fork 0

Use HTTP Accept-Language to detect locale (#1166)

* Use HTTP Accept-Language to detect locale

* Fix gem order to comply with codeclimate

* Sort gem to comply with rubocop

* I18n.default_locale fallback when there is no accept-language header
gh/stable
David Authier 2017-04-09 18:40:24 +02:00 committed by Eugen
parent b16fbd52b2
commit f0bd439486
3 changed files with 25 additions and 20 deletions

37
Gemfile
View File

@ -21,37 +21,38 @@ gem 'paperclip', '~> 5.1'
gem 'paperclip-av-transcoder' gem 'paperclip-av-transcoder'
gem 'aws-sdk', '>= 2.0' gem 'aws-sdk', '>= 2.0'
gem 'http'
gem 'httplog'
gem 'addressable' gem 'addressable'
gem 'nokogiri'
gem 'link_header'
gem 'ostatus2'
gem 'goldfinger'
gem 'devise' gem 'devise'
gem 'devise-two-factor' gem 'devise-two-factor'
gem 'doorkeeper' gem 'doorkeeper'
gem 'rabl'
gem 'rqrcode'
gem 'twitter-text'
gem 'ox'
gem 'oj'
gem 'hiredis'
gem 'redis', '~>3.2', require: ['redis', 'redis/connection/hiredis']
gem 'fast_blank' gem 'fast_blank'
gem 'goldfinger'
gem 'hiredis'
gem 'htmlentities' gem 'htmlentities'
gem 'simple_form' gem 'http'
gem 'will_paginate' gem 'http_accept_language'
gem 'httplog'
gem 'link_header'
gem 'nokogiri'
gem 'oj'
gem 'ostatus2'
gem 'ox'
gem 'rabl'
gem 'rack-attack' gem 'rack-attack'
gem 'rack-cors', require: 'rack/cors' gem 'rack-cors', require: 'rack/cors'
gem 'rack-timeout'
gem 'rails-settings-cached'
gem 'redis', '~>3.2', require: ['redis', 'redis/connection/hiredis']
gem 'rqrcode'
gem 'ruby-oembed', require: 'oembed'
gem 'sidekiq' gem 'sidekiq'
gem 'sidekiq-unique-jobs' gem 'sidekiq-unique-jobs'
gem 'rails-settings-cached'
gem 'simple-navigation' gem 'simple-navigation'
gem 'simple_form'
gem 'statsd-instrument' gem 'statsd-instrument'
gem 'ruby-oembed', require: 'oembed' gem 'twitter-text'
gem 'rack-timeout'
gem 'tzinfo-data' gem 'tzinfo-data'
gem 'will_paginate'
gem 'react-rails' gem 'react-rails'
gem 'browserify-rails' gem 'browserify-rails'

View File

@ -184,6 +184,7 @@ GEM
http-cookie (1.0.3) http-cookie (1.0.3)
domain_name (~> 0.5) domain_name (~> 0.5)
http-form_data (1.0.1) http-form_data (1.0.1)
http_accept_language (2.1.0)
http_parser.rb (0.6.0) http_parser.rb (0.6.0)
httplog (0.3.2) httplog (0.3.2)
colorize colorize
@ -473,6 +474,7 @@ DEPENDENCIES
hiredis hiredis
htmlentities htmlentities
http http
http_accept_language
httplog httplog
i18n-tasks (~> 0.9.6) i18n-tasks (~> 0.9.6)
jquery-rails jquery-rails
@ -522,4 +524,4 @@ RUBY VERSION
ruby 2.3.1p112 ruby 2.3.1p112
BUNDLED WITH BUNDLED WITH
1.14.3 1.14.5

View File

@ -26,6 +26,8 @@ module Localized
end end
def default_locale def default_locale
ENV.fetch('DEFAULT_LOCALE') { I18n.default_locale } ENV.fetch('DEFAULT_LOCALE') {
http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
}
end end
end end