Commit 48261a07 authored by Dylan Griffith's avatar Dylan Griffith

Revert "i18n: Show translation levels for each language in the UI"

This reverts commit 7aa06e08.
parent 4d9aabd2
...@@ -76,7 +76,7 @@ module PreferencesHelper ...@@ -76,7 +76,7 @@ module PreferencesHelper
def language_choices def language_choices
options_for_select( options_for_select(
selectable_locales_with_translation_level.sort, Gitlab::I18n.selectable_locales.map(&:reverse).sort,
current_user.preferred_language current_user.preferred_language
) )
end end
...@@ -107,18 +107,6 @@ module PreferencesHelper ...@@ -107,18 +107,6 @@ module PreferencesHelper
def default_first_day_of_week def default_first_day_of_week
first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first
end end
def selectable_locales_with_translation_level
Gitlab::I18n.selectable_locales.map do |code, language|
[
s_("i18n|%{language} (%{percent_translated}%% translated)") % {
language: language,
percent_translated: Gitlab::I18n.percentage_translated_for(code)
},
code
]
end
end
end end
PreferencesHelper.prepend_if_ee('EE::PreferencesHelper') PreferencesHelper.prepend_if_ee('EE::PreferencesHelper')
...@@ -431,7 +431,7 @@ class User < ApplicationRecord ...@@ -431,7 +431,7 @@ class User < ApplicationRecord
def preferred_language def preferred_language
read_attribute('preferred_language') || read_attribute('preferred_language') ||
I18n.default_locale.to_s.presence_in(Gitlab::I18n.available_locales) || I18n.default_locale.to_s.presence_in(Gitlab::I18n::AVAILABLE_LANGUAGES.keys) ||
'en' 'en'
end end
......
---
title: Add the translation level for each language in the user profile language selector
merge_request: 59420
author:
type: changed
...@@ -78,10 +78,3 @@ recreate it with the following steps: ...@@ -78,10 +78,3 @@ recreate it with the following steps:
1. Select the `gitlab-org/gitlab` repository. 1. Select the `gitlab-org/gitlab` repository.
1. In `Select Branches for Translation`, select `master`. 1. In `Select Branches for Translation`, select `master`.
1. Ensure the `Service Branch Name` is `master-i18n`. 1. Ensure the `Service Branch Name` is `master-i18n`.
## Manually update the translation levels
There's no automated way to pull the translation levels from CrowdIn, to display
this information in the language selection dropdown. Therefore, the translation
levels are hard-coded in the `TRANSLATION_LEVELS` constant in [`i18n.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/i18n.rb),
and must be regularly updated.
...@@ -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',
...@@ -28,49 +42,9 @@ module Gitlab ...@@ -28,49 +42,9 @@ module Gitlab
'zh_HK' => 'Chinese, Traditional (Hong Kong) - 繁體中文 (香港)', 'zh_HK' => 'Chinese, Traditional (Hong Kong) - 繁體中文 (香港)',
'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)' 'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)'
}.freeze }.freeze
private_constant :AVAILABLE_LANGUAGES
# Languages with less then MINIMUM_TRANSLATION_LEVEL% of available translations will not
# be available in the UI.
# https://gitlab.com/gitlab-org/gitlab/-/issues/221012
MINIMUM_TRANSLATION_LEVEL = 2
# Currently monthly updated manually by ~group::import PM.
# https://gitlab.com/gitlab-org/gitlab/-/issues/18923
TRANSLATION_LEVELS = {
'bg' => 1,
'cs_CZ' => 1,
'de' => 20,
'en' => 100,
'eo' => 1,
'es' => 44,
'fil_PH' => 1,
'fr' => 14,
'gl_ES' => 1,
'id_ID' => 0,
'it' => 3,
'ja' => 49,
'ko' => 15,
'nl_NL' => 1,
'pl_PL' => 1,
'pt_BR' => 23,
'ru' => 34,
'tr_TR' => 18,
'uk' => 46,
'zh_CN' => 78,
'zh_HK' => 3,
'zh_TW' => 4
}.freeze
private_constant :TRANSLATION_LEVELS
def selectable_locales def selectable_locales
@selectable_locales ||= AVAILABLE_LANGUAGES.reject do |code, _name| AVAILABLE_LANGUAGES.reject { |key, _value| NOT_AVAILABLE_IN_UI.include? key }
percentage_translated_for(code) < MINIMUM_TRANSLATION_LEVEL
end
end
def percentage_translated_for(code)
TRANSLATION_LEVELS.fetch(code, 0)
end end
def available_locales def available_locales
......
...@@ -37939,9 +37939,6 @@ msgstr "" ...@@ -37939,9 +37939,6 @@ msgstr ""
msgid "https://your-bitbucket-server" msgid "https://your-bitbucket-server"
msgstr "" msgstr ""
msgid "i18n|%{language} (%{percent_translated}%% translated)"
msgstr ""
msgid "image diff" msgid "image diff"
msgstr "" msgstr ""
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe 'User edit preferences profile', :js do RSpec.describe 'User edit preferences profile', :js do
...@@ -64,4 +63,17 @@ RSpec.describe 'User edit preferences profile', :js do ...@@ -64,4 +63,17 @@ RSpec.describe 'User edit preferences profile', :js 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.selectable_locales.values,
visible: :all
)
end
end
end end
...@@ -121,23 +121,6 @@ RSpec.describe PreferencesHelper do ...@@ -121,23 +121,6 @@ RSpec.describe PreferencesHelper do
end end
end end
describe '#language_choices' do
it 'lists all the selectable language options with their translation percent' do
stub_const(
'Gitlab::I18n::TRANSLATION_LEVELS',
'en' => 100,
'es' => 65
)
stub_user(preferred_language: :en)
expect(helper.language_choices).to eq([
'<option selected="selected" value="en">English (100% translated)</option>',
'<option value="es">Spanish - español (65% translated)</option>'
].join("\n"))
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)
......
...@@ -3,21 +3,13 @@ ...@@ -3,21 +3,13 @@
require 'spec_helper' 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 describe '.selectable_locales' do
it 'does not return languages with low translation levels', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/329723' do it 'does not return languages that should not be available in the UI' do
stub_const( Gitlab::I18n::NOT_AVAILABLE_IN_UI.each do |language|
'Gitlab::I18n::TRANSLATION_LEVELS', expect(described_class.selectable_locales).not_to include(language)
'pt_BR' => 0, end
'en' => 100,
'es' => 65
)
expect(described_class.selectable_locales).to eq({
'en' => 'English',
'es' => 'Spanish - español'
})
end end
end end
......
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