Fix Rubocop complains plus some small refactor

This commit is contained in:
Ruben Davila 2017-04-19 23:19:24 -05:00
parent 302e855f52
commit 1de135bc04
5 changed files with 13 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

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