Commit 787296d7 authored by Kassio Borges's avatar Kassio Borges

Use `User#preferred_language` language as default

Instead of using `Gitlab::I18n::AVAILABLE_LANGUAGES` order to define the
user default language in the UI, use the `User#preferred_language`.
`User#preferred_language` is set by default with `I18n.default_locale`.
parent e8979927
...@@ -70,7 +70,10 @@ module PreferencesHelper ...@@ -70,7 +70,10 @@ module PreferencesHelper
end end
def language_choices def language_choices
Gitlab::I18n::AVAILABLE_LANGUAGES.map(&:reverse).sort options_for_select(
Gitlab::I18n::AVAILABLE_LANGUAGES.map(&:reverse).sort,
current_user.preferred_language
)
end end
private private
......
---
title: "Use the user's preferred language as default"
merge_request: 35676
author:
type: fixed
...@@ -56,4 +56,17 @@ RSpec.describe 'User edit preferences profile' do ...@@ -56,4 +56,17 @@ RSpec.describe 'User edit preferences profile' do
expect(page).to have_content('Failed to save preferences') expect(page).to have_content('Failed to save preferences')
end end
end end
describe 'User language' do
let(:user) { create(:user, preferred_language: :es) }
it 'shows the user preferred language by default' do
expect(page).to have_select(
'user[preferred_language]',
selected: 'Spanish - español',
options: Gitlab::I18n::AVAILABLE_LANGUAGES.values,
visible: :all
)
end
end
end end
...@@ -120,13 +120,6 @@ RSpec.describe PreferencesHelper do ...@@ -120,13 +120,6 @@ RSpec.describe PreferencesHelper do
end end
end end
describe '#language_choices' do
it 'returns an array of all available languages' do
expect(helper.language_choices).to be_an(Array)
expect(helper.language_choices.map(&:first)).to eq(Gitlab::I18n::AVAILABLE_LANGUAGES.values.sort)
end
end
def stub_user(messages = {}) def stub_user(messages = {})
if messages.empty? if messages.empty?
allow(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:current_user).and_return(nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment