Set locale through controller filter

This commit is contained in:
Ruben Davila 2017-04-13 01:03:47 -05:00
parent 020e12a6ae
commit 73d0730d09
11 changed files with 86 additions and 15 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -1,9 +1,9 @@
module Gitlab
module I18n
AVAILABLE_LANGUAGES = [
[_('English'), 'en'],
[_('Spanish'), 'es'],
[_('Deutsch'), 'de']
['English', 'en'],
['Spanish', 'es'],
['Deutsch', 'de']
]
end
end

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-12 22:36-0500\n"
"POT-Creation-Date: 2017-04-13 00:01-0500\n"
"PO-Revision-Date: 2017-04-12 22:37-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: German\n"
@ -17,3 +17,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
msgid "Deutsch"
msgstr ""
msgid "English"
msgstr ""
msgid "Spanish"
msgstr ""

View file

@ -16,3 +16,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
msgid "Deutsch"
msgstr ""
msgid "English"
msgstr ""
msgid "Spanish"
msgstr ""

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-12 22:36-0500\n"
"POT-Creation-Date: 2017-04-13 00:01-0500\n"
"PO-Revision-Date: 2017-04-12 22:36-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: English\n"
@ -17,3 +17,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
msgid "Deutsch"
msgstr ""
msgid "English"
msgstr ""
msgid "Spanish"
msgstr ""

View file

@ -16,3 +16,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
msgid "Deutsch"
msgstr ""
msgid "English"
msgstr ""
msgid "Spanish"
msgstr ""

View file

@ -7,13 +7,22 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-12 22:36-0500\n"
"PO-Revision-Date: 2017-04-12 22:37-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"PO-Revision-Date: 2017-04-13 00:07-0500\n"
"Language-Team: Spanish\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
"POT-Creation-Date: 2017-04-13 00:01-0500\n"
"Last-Translator: \n"
"X-Generator: Poedit 2.0.1\n"
msgid "Deutsch"
msgstr "Alemán"
msgid "English"
msgstr "Inglés"
msgid "Spanish"
msgstr "Español"

View file

@ -7,12 +7,21 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2017-04-12 22:37-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"PO-Revision-Date: 2017-04-13 00:07-0500\n"
"Language-Team: Spanish\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"
"Last-Translator: \n"
"X-Generator: Poedit 2.0.1\n"
msgid "Deutsch"
msgstr "Alemán"
msgid "English"
msgstr "Inglés"
msgid "Spanish"
msgstr "Español"

View file

@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-12 22:36-0500\n"
"PO-Revision-Date: 2017-04-12 22:36-0500\n"
"POT-Creation-Date: 2017-04-13 00:01-0500\n"
"PO-Revision-Date: 2017-04-13 00:01-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
@ -17,3 +17,12 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
msgid "Deutsch"
msgstr ""
msgid "English"
msgstr ""
msgid "Spanish"
msgstr ""