about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Authier <aweaoftheworld@gmail.com>2017-04-09 18:40:24 +0200
committerEugen <eugen@zeonfederated.com>2017-04-09 18:40:24 +0200
commitf0bd4394869305fc6605463efff53ecc6ff61046 (patch)
tree41c43583d8f7300ec34d4c1dc327fcf0bf29bf77
parentb16fbd52b2c5471d401dbfe397a3e7dbaaa21225 (diff)
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
-rw-r--r--Gemfile37
-rw-r--r--Gemfile.lock4
-rw-r--r--app/controllers/concerns/localized.rb4
3 files changed, 25 insertions, 20 deletions
diff --git a/Gemfile b/Gemfile
index 65bd5eb49..7895a345c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,37 +21,38 @@ gem 'paperclip', '~> 5.1'
 gem 'paperclip-av-transcoder'
 gem 'aws-sdk', '>= 2.0'
 
-gem 'http'
-gem 'httplog'
 gem 'addressable'
-gem 'nokogiri'
-gem 'link_header'
-gem 'ostatus2'
-gem 'goldfinger'
 gem 'devise'
 gem 'devise-two-factor'
 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 'goldfinger'
+gem 'hiredis'
 gem 'htmlentities'
-gem 'simple_form'
-gem 'will_paginate'
+gem 'http'
+gem 'http_accept_language'
+gem 'httplog'
+gem 'link_header'
+gem 'nokogiri'
+gem 'oj'
+gem 'ostatus2'
+gem 'ox'
+gem 'rabl'
 gem 'rack-attack'
 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-unique-jobs'
-gem 'rails-settings-cached'
 gem 'simple-navigation'
+gem 'simple_form'
 gem 'statsd-instrument'
-gem 'ruby-oembed', require: 'oembed'
-gem 'rack-timeout'
+gem 'twitter-text'
 gem 'tzinfo-data'
+gem 'will_paginate'
 
 gem 'react-rails'
 gem 'browserify-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index f2a199931..aa048aace 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -184,6 +184,7 @@ GEM
     http-cookie (1.0.3)
       domain_name (~> 0.5)
     http-form_data (1.0.1)
+    http_accept_language (2.1.0)
     http_parser.rb (0.6.0)
     httplog (0.3.2)
       colorize
@@ -473,6 +474,7 @@ DEPENDENCIES
   hiredis
   htmlentities
   http
+  http_accept_language
   httplog
   i18n-tasks (~> 0.9.6)
   jquery-rails
@@ -522,4 +524,4 @@ RUBY VERSION
    ruby 2.3.1p112
 
 BUNDLED WITH
-   1.14.3
+   1.14.5
diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb
index 6528ce45e..bcf3fd0a0 100644
--- a/app/controllers/concerns/localized.rb
+++ b/app/controllers/concerns/localized.rb
@@ -26,6 +26,8 @@ module Localized
   end
 
   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