diff --git a/src/api-umbrella/web-app/Gemfile b/src/api-umbrella/web-app/Gemfile index 8fb8cf317..545d77788 100644 --- a/src/api-umbrella/web-app/Gemfile +++ b/src/api-umbrella/web-app/Gemfile @@ -98,7 +98,7 @@ gem "premailer-rails", "~> 1.9.4" gem "nokogiri", "~> 1.6.8" # Localization in the admin based on the Accept-Language header -gem "http_accept_language", "~> 2.0.5" +gem "http_accept_language", "~> 2.1.0" # Markdown gem "kramdown", "~> 1.12.0" diff --git a/src/api-umbrella/web-app/Gemfile.lock b/src/api-umbrella/web-app/Gemfile.lock index f0c62c71d..2a8fab012 100644 --- a/src/api-umbrella/web-app/Gemfile.lock +++ b/src/api-umbrella/web-app/Gemfile.lock @@ -147,7 +147,7 @@ GEM activesupport (>= 4.1.0) hashie (3.4.6) htmlentities (4.3.4) - http_accept_language (2.0.5) + http_accept_language (2.1.0) i18n (0.7.0) i18n-js (3.0.0.rc14) i18n (~> 0.6, >= 0.6.6) @@ -327,7 +327,7 @@ DEPENDENCIES delayed_job_mongoid (~> 2.2.0) devise (~> 4.2.0) elasticsearch (~> 2.0.0) - http_accept_language (~> 2.0.5) + http_accept_language (~> 2.1.0) i18n-js (>= 3.0.0.rc13) jbuilder (~> 2.6.0) kramdown (~> 1.12.0) @@ -366,4 +366,4 @@ DEPENDENCIES sequel (~> 4.37.0) BUNDLED WITH - 1.13.5 + 1.13.6 diff --git a/src/api-umbrella/web-app/app/controllers/admin/base_controller.rb b/src/api-umbrella/web-app/app/controllers/admin/base_controller.rb index 7f591fe43..9359c0646 100644 --- a/src/api-umbrella/web-app/app/controllers/admin/base_controller.rb +++ b/src/api-umbrella/web-app/app/controllers/admin/base_controller.rb @@ -2,11 +2,4 @@ class Admin::BaseController < ApplicationController before_action :authenticate_admin! after_action :verify_authorized skip_after_action :verify_authorized, :only => [:empty] - before_action :set_locale - - private - - def set_locale - I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale - end end diff --git a/src/api-umbrella/web-app/app/controllers/admin/sessions_controller.rb b/src/api-umbrella/web-app/app/controllers/admin/sessions_controller.rb index fca11bf2d..9920f7fd3 100644 --- a/src/api-umbrella/web-app/app/controllers/admin/sessions_controller.rb +++ b/src/api-umbrella/web-app/app/controllers/admin/sessions_controller.rb @@ -1,5 +1,4 @@ class Admin::SessionsController < Devise::SessionsController - before_action :set_locale skip_after_action :verify_authorized def new @@ -25,10 +24,4 @@ def auth format.json { render(:json => response) } end end - - private - - def set_locale - I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale - end end diff --git a/src/api-umbrella/web-app/app/controllers/application_controller.rb b/src/api-umbrella/web-app/app/controllers/application_controller.rb index 1699fc55e..ce205770e 100644 --- a/src/api-umbrella/web-app/app/controllers/application_controller.rb +++ b/src/api-umbrella/web-app/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ class ApplicationController < ActionController::Base include Pundit include DatatablesHelper + prepend_around_filter :use_locale protect_from_forgery :with => :null_session around_action :set_userstamp @@ -81,6 +82,13 @@ def parse_post_for_pseudo_ie_cors end end + def use_locale + locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale + I18n.with_locale(locale) do + yield + end + end + def set_analytics_adapter if(params[:beta_analytics] == "true") @analytics_adapter = "kylin"