From 73d0730d09b5f9a9b68f158cc72ad30c7a2b35d0 Mon Sep 17 00:00:00 2001 From: Ruben Davila Date: Thu, 13 Apr 2017 01:03:47 -0500 Subject: Set locale through controller filter --- app/controllers/application_controller.rb | 6 ++++++ app/controllers/profiles_controller.rb | 1 + app/views/profiles/show.html.haml | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app') 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" -- cgit v1.2.1