Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
86b7e30423
commit
036de62f73
|
@ -1 +1 @@
|
|||
2.9.0
|
||||
2.10.0
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
module PreferencesHelper
|
||||
def layout_choices
|
||||
[
|
||||
['Fixed', :fixed],
|
||||
['Fluid', :fluid]
|
||||
['Fixed', :fixed],
|
||||
['Fluid', :fluid]
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ module PreferencesHelper
|
|||
|
||||
def language_choices
|
||||
options_for_select(
|
||||
selectable_locales_with_translation_level.sort,
|
||||
Gitlab::I18n.selectable_locales.map(&:reverse).sort,
|
||||
current_user.preferred_language
|
||||
)
|
||||
end
|
||||
|
@ -107,18 +107,6 @@ module PreferencesHelper
|
|||
def default_first_day_of_week
|
||||
first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first
|
||||
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
|
||||
|
||||
PreferencesHelper.prepend_if_ee('EE::PreferencesHelper')
|
||||
|
|
|
@ -431,7 +431,7 @@ class User < ApplicationRecord
|
|||
|
||||
def 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'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
---
|
||||
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:
|
|||
1. Select the `gitlab-org/gitlab` repository.
|
||||
1. In `Select Branches for Translation`, select `master`.
|
||||
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
|
|||
module I18n
|
||||
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 = {
|
||||
'bg' => 'Bulgarian - български',
|
||||
'cs_CZ' => 'Czech - čeština',
|
||||
|
@ -28,49 +42,9 @@ module Gitlab
|
|||
'zh_HK' => 'Chinese, Traditional (Hong Kong) - 繁體中文 (香港)',
|
||||
'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)'
|
||||
}.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
|
||||
@selectable_locales ||= AVAILABLE_LANGUAGES.reject do |code, _name|
|
||||
percentage_translated_for(code) < MINIMUM_TRANSLATION_LEVEL
|
||||
end
|
||||
end
|
||||
|
||||
def percentage_translated_for(code)
|
||||
TRANSLATION_LEVELS.fetch(code, 0)
|
||||
AVAILABLE_LANGUAGES.reject { |key, _value| NOT_AVAILABLE_IN_UI.include? key }
|
||||
end
|
||||
|
||||
def available_locales
|
||||
|
|
|
@ -37939,9 +37939,6 @@ msgstr ""
|
|||
msgid "https://your-bitbucket-server"
|
||||
msgstr ""
|
||||
|
||||
msgid "i18n|%{language} (%{percent_translated}%% translated)"
|
||||
msgstr ""
|
||||
|
||||
msgid "image diff"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
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.')
|
||||
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
|
||||
|
|
|
@ -121,23 +121,6 @@ RSpec.describe PreferencesHelper do
|
|||
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 = {})
|
||||
if messages.empty?
|
||||
allow(helper).to receive(:current_user).and_return(nil)
|
||||
|
|
|
@ -3,21 +3,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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 with low translation levels', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/329723' do
|
||||
stub_const(
|
||||
'Gitlab::I18n::TRANSLATION_LEVELS',
|
||||
'pt_BR' => 0,
|
||||
'en' => 100,
|
||||
'es' => 65
|
||||
)
|
||||
|
||||
expect(described_class.selectable_locales).to eq({
|
||||
'en' => 'English',
|
||||
'es' => 'Spanish - español'
|
||||
})
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue