Commit a32fd49d authored by Fabian Schneider's avatar Fabian Schneider Committed by Stan Hu

Move language setting to preferences

parent 09532e38
......@@ -37,6 +37,14 @@ class Profiles::PreferencesController < Profiles::ApplicationController
end
def preferences_param_names
[:color_scheme_id, :layout, :dashboard, :project_view, :theme_id, :first_day_of_week]
[
:color_scheme_id,
:layout,
:dashboard,
:project_view,
:theme_id,
:first_day_of_week,
:preferred_language
]
end
end
......@@ -104,7 +104,6 @@ class ProfilesController < Profiles::ApplicationController
:username,
:website_url,
:organization,
:preferred_language,
:private_profile,
:include_private_contributions,
status: [:emoji, :message]
......
......@@ -62,6 +62,10 @@ module PreferencesHelper
Gitlab::ColorSchemes.for_user(current_user).css_class
end
def language_choices
Gitlab::I18n::AVAILABLE_LANGUAGES.map { |value, label| [label, value] }
end
private
# Ensure that anyone adding new options updates `DASHBOARD_CHOICES` too
......
......@@ -72,6 +72,12 @@
= succeed '.' do
= link_to _('Learn more'), help_page_path('user/profile/preferences', anchor: 'localization'), target: '_blank'
.col-lg-8
.form-group
= f.label :preferred_language, class: 'label-bold' do
= _('Language')
= f.select :preferred_language, language_choices, {}, class: 'select2'
.form-text.text-muted
= s_('Preferences|This feature is experimental and translations are not complete yet')
.form-group
= f.label :first_day_of_week, class: 'label-bold' do
= _('First day of the week')
......
......@@ -95,9 +95,6 @@
= f.select :commit_email, options_for_select(commit_email_select_options(@user), selected: selected_commit_email(@user)),
{ help: s_("Profiles|This email will be used for web based operations, such as edits and merges. %{learn_more}").html_safe % { learn_more: commit_email_docs_link } },
control_class: 'select2 input-lg'
= f.select :preferred_language, Gitlab::I18n::AVAILABLE_LANGUAGES.map { |value, label| [label, value] },
{ help: s_("Profiles|This feature is experimental and translations are not complete yet") },
control_class: 'select2 input-lg'
= f.text_field :skype, class: 'input-md', placeholder: s_("Profiles|username")
= f.text_field :linkedin, class: 'input-md', help: s_("Profiles|Your LinkedIn profile name from linkedin.com/in/profilename")
= f.text_field :twitter, class: 'input-md', placeholder: s_("Profiles|@username")
......
---
title: Move language setting to preferences
merge_request: 25427
author: Fabian Schneider @fabsrc
type: changed
......@@ -93,6 +93,12 @@ You can choose between 3 options:
## Localization
### Language
Select your preferred language from a list of supported languages.
*This feature is experimental and translations are not complete yet.*
### First day of the week
The first day of the week can be customised for calendar views and date pickers.
......
......@@ -4271,6 +4271,9 @@ msgstr ""
msgid "Labels|Promoting %{labelTitle} will make it available for all projects inside %{groupName}. Existing project labels with the same title will be merged. This action cannot be reversed."
msgstr ""
msgid "Language"
msgstr ""
msgid "Large File Storage"
msgstr ""
......@@ -5530,6 +5533,9 @@ msgstr ""
msgid "Preferences|Navigation theme"
msgstr ""
msgid "Preferences|This feature is experimental and translations are not complete yet"
msgstr ""
msgid "Press Enter or click to search"
msgstr ""
......@@ -5722,9 +5728,6 @@ msgstr ""
msgid "Profiles|This emoji and message will appear on your profile and throughout the interface."
msgstr ""
msgid "Profiles|This feature is experimental and translations are not complete yet"
msgstr ""
msgid "Profiles|This information will appear on your profile"
msgstr ""
......
......@@ -43,7 +43,8 @@ describe Profiles::PreferencesController do
color_scheme_id: '1',
dashboard: 'stars',
theme_id: '2',
first_day_of_week: '1'
first_day_of_week: '1',
preferred_language: 'jp'
}.with_indifferent_access
expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!)
......
require 'spec_helper'
describe 'User visits the profile preferences page' do
include Select2Helper
let(:user) { create(:user) }
before do
......@@ -60,6 +62,28 @@ describe 'User visits the profile preferences page' do
end
end
describe 'User changes their language', :js do
it 'creates a flash message' do
select2('en', from: '#user_preferred_language')
click_button 'Save'
wait_for_requests
expect_preferences_saved_message
end
it 'updates their preference' do
wait_for_requests
select2('eo', from: '#user_preferred_language')
click_button 'Save'
wait_for_requests
refresh
expect(page).to have_css('html[lang="eo"]')
end
end
def expect_preferences_saved_message
page.within('.flash-container') do
expect(page).to have_content('Preferences saved.')
......
......@@ -110,6 +110,13 @@ describe PreferencesHelper do
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(&:second)).to eq(Gitlab::I18n.available_locales)
end
end
def stub_user(messages = {})
if messages.empty?
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