From 759803708077dc061ec4449395abb3505486e4fd Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 4 Mar 2016 23:17:14 +1100 Subject: [PATCH] Only pull in gem if it is being used, remove middleware --- Gemfile | 2 +- app/controllers/application_controller.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index bac86ca0c26..9ccf3da501d 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem 'active_model_serializers', '~> 0.8.3' gem 'onebox' -gem 'http_accept_language', '~>2.0.5' +gem 'http_accept_language', '~>2.0.5', require: false gem 'ember-rails' gem 'ember-source', '1.12.2' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2e2462ec96a..8a09c8fbee7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -321,8 +321,10 @@ class ApplicationController < ActionController::Base begin # Rails I18n uses underscores between the locale and the region; the request # headers use hyphens. + require 'http_accept_language' unless defined? HttpAcceptLanguage available_locales = I18n.available_locales.map { |locale| locale.to_s.gsub(/_/, '-') } - http_accept_language.language_region_compatible_from(available_locales).gsub(/-/, '_') + parser = HttpAcceptLanguage::Parser.new(request.env["HTTP_ACCEPT_LANGUAGE"]) + parser.language_region_compatible_from(available_locales).gsub(/-/, '_') rescue # If Accept-Language headers are not set. I18n.default_locale