summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-04-13 01:03:47 -0500
committerRuben Davila <rdavila84@gmail.com>2017-04-13 01:03:47 -0500
commit73d0730d09b5f9a9b68f158cc72ad30c7a2b35d0 (patch)
tree3443759bd564dca586716c46d6dd8c74594432e7 /app
parent020e12a6ae99e9b9dfaa3cfbd640ecdf31d7424d (diff)
downloadgitlab-ce-73d0730d09b5f9a9b68f158cc72ad30c7a2b35d0.tar.gz
Set locale through controller filter
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--app/controllers/profiles_controller.rb1
-rw-r--r--app/views/profiles/show.html.haml3
3 files changed, 9 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e77094fe2a8..5a3bd4040cc 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -265,4 +265,10 @@ class ApplicationController < ActionController::Base
def u2f_app_id
request.base_url
end
+
+ def set_locale
+ requested_locale = current_user&.preferred_language || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
+ locale = FastGettext.set_locale(requested_locale)
+ I18n.locale = locale
+ end
end
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 57e23cea00e..0f01bf7e706 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -3,6 +3,7 @@ class ProfilesController < Profiles::ApplicationController
before_action :user
before_action :authorize_change_username!, only: :update_username
+ before_action :set_locale, only: :show
skip_before_action :require_email, only: [:show, :update]
def show
diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml
index dc71a04cbf0..d8ef64ceb72 100644
--- a/app/views/profiles/show.html.haml
+++ b/app/views/profiles/show.html.haml
@@ -74,7 +74,8 @@
%span.help-block This email will be displayed on your public profile.
.form-group
= f.label :preferred_language, class: "label-light"
- = f.select :preferred_language, Gitlab::I18n::AVAILABLE_LANGUAGES, {}, class: "select2"
+ = f.select :preferred_language, Gitlab::I18n::AVAILABLE_LANGUAGES.map { |lang| [_(lang[0]), lang[1]] },
+ {}, class: "select2"
.form-group
= f.label :skype, class: "label-light"
= f.text_field :skype, class: "form-control"