diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a3bd4040cc..0af05992cce 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -269,6 +269,7 @@ class ApplicationController < ActionController::Base 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/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index d8ef64ceb72..9846f01603f 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -74,7 +74,7 @@ %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.map { |lang| [_(lang[0]), lang[1]] }, + = f.select :preferred_language, Gitlab::I18n::AVAILABLE_LANGUAGES.map { |value, label| [_(label), value] }, {}, class: "select2" .form-group = f.label :skype, class: "label-light" diff --git a/config/initializers/fast_gettext.rb b/config/initializers/fast_gettext.rb index cfc3427b5ae..54b0049033b 100644 --- a/config/initializers/fast_gettext.rb +++ b/config/initializers/fast_gettext.rb @@ -1,3 +1,3 @@ FastGettext.add_text_domain 'gitlab', path: 'locale', type: :po -FastGettext.default_available_locales = ['en', 'es','de'] +FastGettext.default_available_locales = Gitlab::I18n::AVAILABLE_LANGUAGES.keys FastGettext.default_text_domain = 'gitlab' diff --git a/db/migrate/20170413035209_add_preferred_language_to_users.rb b/db/migrate/20170413035209_add_preferred_language_to_users.rb index 5dc128dbaea..6fe91656eeb 100644 --- a/db/migrate/20170413035209_add_preferred_language_to_users.rb +++ b/db/migrate/20170413035209_add_preferred_language_to_users.rb @@ -8,7 +8,11 @@ class AddPreferredLanguageToUsers < ActiveRecord::Migration disable_ddl_transaction! - def change + def up add_column_with_default :users, :preferred_language, :string, default: 'en' end + + def down + remove_column :users, :preferred_language + end end diff --git a/lib/gitlab/i18n.rb b/lib/gitlab/i18n.rb index 85e527afd71..0459def6517 100644 --- a/lib/gitlab/i18n.rb +++ b/lib/gitlab/i18n.rb @@ -1,9 +1,9 @@ module Gitlab module I18n - AVAILABLE_LANGUAGES = [ - ['English', 'en'], - ['Spanish', 'es'], - ['Deutsch', 'de'] - ] + AVAILABLE_LANGUAGES = { + 'en' => 'English', + 'es' => 'Spanish', + 'de' => 'Deutsch' + }.freeze end end