Commit bbf94418 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'kassio/remove-languages-from-ui' into 'master'

Remove languages with low number of translations

See merge request gitlab-org/gitlab!38312
parents a52302b5 0a48ef0f
...@@ -71,7 +71,7 @@ module PreferencesHelper ...@@ -71,7 +71,7 @@ module PreferencesHelper
def language_choices def language_choices
options_for_select( options_for_select(
Gitlab::I18n::AVAILABLE_LANGUAGES.map(&:reverse).sort, Gitlab::I18n.selectable_locales.map(&:reverse).sort,
current_user.preferred_language current_user.preferred_language
) )
end end
......
---
title: Hide languages with few translations
merge_request: 38312
author:
type: changed
...@@ -650,6 +650,10 @@ aren't in the message with ID `1 pipeline`. ...@@ -650,6 +650,10 @@ aren't in the message with ID `1 pipeline`.
## Adding a new language ## Adding a new language
NOTE: **Note:**
[Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/221012) in GitLab 13.3:
Languages with less than 2% of translations won't be available in the UI.
Let's suppose you want to add translations for a new language, let's say French. Let's suppose you want to add translations for a new language, let's say French.
1. The first step is to register the new language in `lib/gitlab/i18n.rb`: 1. The first step is to register the new language in `lib/gitlab/i18n.rb`:
......
...@@ -4,6 +4,20 @@ module Gitlab ...@@ -4,6 +4,20 @@ module Gitlab
module I18n module I18n
extend self extend self
# Languages with less then 2% of available translations will not
# be available in the UI.
# https://gitlab.com/gitlab-org/gitlab/-/issues/221012
NOT_AVAILABLE_IN_UI = %w[
fil_PH
pl_PL
nl_NL
id_ID
cs_CZ
bg
eo
gl_ES
].freeze
AVAILABLE_LANGUAGES = { AVAILABLE_LANGUAGES = {
'bg' => 'Bulgarian - български', 'bg' => 'Bulgarian - български',
'cs_CZ' => 'Czech - čeština', 'cs_CZ' => 'Czech - čeština',
...@@ -29,6 +43,10 @@ module Gitlab ...@@ -29,6 +43,10 @@ module Gitlab
'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)' 'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)'
}.freeze }.freeze
def selectable_locales
AVAILABLE_LANGUAGES.reject { |key, _value| NOT_AVAILABLE_IN_UI.include? key }
end
def available_locales def available_locales
AVAILABLE_LANGUAGES.keys AVAILABLE_LANGUAGES.keys
end end
......
...@@ -64,7 +64,7 @@ RSpec.describe 'User edit preferences profile' do ...@@ -64,7 +64,7 @@ RSpec.describe 'User edit preferences profile' do
expect(page).to have_select( expect(page).to have_select(
'user[preferred_language]', 'user[preferred_language]',
selected: 'Spanish - español', selected: 'Spanish - español',
options: Gitlab::I18n::AVAILABLE_LANGUAGES.values, options: Gitlab::I18n.selectable_locales.values,
visible: :all visible: :all
) )
end end
......
...@@ -76,13 +76,13 @@ RSpec.describe 'User visits the profile preferences page' do ...@@ -76,13 +76,13 @@ RSpec.describe 'User visits the profile preferences page' do
it 'updates their preference' do it 'updates their preference' do
wait_for_requests wait_for_requests
select2('eo', from: '#user_preferred_language') select2('pt_BR', from: '#user_preferred_language')
click_button 'Save' click_button 'Save'
wait_for_requests wait_for_requests
refresh refresh
expect(page).to have_css('html[lang="eo"]') expect(page).to have_css('html[lang="pt-BR"]')
end end
end end
......
...@@ -5,6 +5,14 @@ require 'spec_helper' ...@@ -5,6 +5,14 @@ require 'spec_helper'
RSpec.describe Gitlab::I18n do RSpec.describe Gitlab::I18n do
let(:user) { create(:user, preferred_language: 'es') } let(:user) { create(:user, preferred_language: 'es') }
describe '.selectable_locales' do
it 'does not return languages that should not be available in the UI' do
Gitlab::I18n::NOT_AVAILABLE_IN_UI.each do |language|
expect(described_class.selectable_locales).not_to include(language)
end
end
end
describe '.locale=' do describe '.locale=' do
after do after do
described_class.use_default_locale described_class.use_default_locale
......
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