Skip to content

Commit

Permalink
Fix I18n not always resetting across multiple requests.
Browse files Browse the repository at this point in the history
This could lead to strange responses in a foreign language if a request
was made in that language earlier, and subsequent requests managed to
hit the right area on the same thread.
  • Loading branch information
GUI committed Nov 27, 2016
1 parent 19bb9b4 commit 2a98714
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api-umbrella/web-app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/api-umbrella/web-app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -366,4 +366,4 @@ DEPENDENCIES
sequel (~> 4.37.0)

BUNDLED WITH
1.13.5
1.13.6
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Admin::SessionsController < Devise::SessionsController
before_action :set_locale
skip_after_action :verify_authorized

def new
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2a98714

Please sign in to comment.