2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-13 04:23:02 +00:00
|
|
|
module Gitlab
|
|
|
|
module I18n
|
2017-05-03 04:36:36 +00:00
|
|
|
extend self
|
|
|
|
|
2017-04-20 04:19:24 +00:00
|
|
|
AVAILABLE_LANGUAGES = {
|
2020-05-05 03:09:46 +00:00
|
|
|
'bg' => 'Bulgarian - български',
|
|
|
|
'cs_CZ' => 'Czech - čeština',
|
2021-08-31 12:11:07 +00:00
|
|
|
'da_DK' => 'Danish - dansk',
|
2020-05-05 03:09:46 +00:00
|
|
|
'de' => 'German - Deutsch',
|
2017-05-04 23:44:19 +00:00
|
|
|
'en' => 'English',
|
2020-05-05 03:09:46 +00:00
|
|
|
'eo' => 'Esperanto - esperanto',
|
|
|
|
'es' => 'Spanish - español',
|
2018-05-14 13:20:38 +00:00
|
|
|
'fil_PH' => 'Filipino',
|
2020-05-05 03:09:46 +00:00
|
|
|
'fr' => 'French - français',
|
|
|
|
'gl_ES' => 'Galician - galego',
|
|
|
|
'id_ID' => 'Indonesian - Bahasa Indonesia',
|
|
|
|
'it' => 'Italian - italiano',
|
|
|
|
'ja' => 'Japanese - 日本語',
|
|
|
|
'ko' => 'Korean - 한국어',
|
2021-08-31 12:11:07 +00:00
|
|
|
'nb_NO' => 'Norwegian (Bokmål) - norsk (bokmål)',
|
2020-05-05 03:09:46 +00:00
|
|
|
'nl_NL' => 'Dutch - Nederlands',
|
|
|
|
'pl_PL' => 'Polish - polski',
|
|
|
|
'pt_BR' => 'Portuguese (Brazil) - português (Brasil)',
|
2021-08-31 12:11:07 +00:00
|
|
|
'ro_RO' => 'Romanian - română',
|
|
|
|
'ru' => 'Russian - русский',
|
2020-05-05 03:09:46 +00:00
|
|
|
'tr_TR' => 'Turkish - Türkçe',
|
|
|
|
'uk' => 'Ukrainian - українська',
|
|
|
|
'zh_CN' => 'Chinese, Simplified - 简体中文',
|
|
|
|
'zh_HK' => 'Chinese, Traditional (Hong Kong) - 繁體中文 (香港)',
|
|
|
|
'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)'
|
2017-04-20 04:19:24 +00:00
|
|
|
}.freeze
|
2021-05-10 00:10:37 +00:00
|
|
|
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 = {
|
2021-08-09 18:08:33 +00:00
|
|
|
'bg' => 0,
|
2021-09-02 12:11:03 +00:00
|
|
|
'cs_CZ' => 0,
|
2022-05-02 15:10:10 +00:00
|
|
|
'da_DK' => 43,
|
2022-04-04 12:08:38 +00:00
|
|
|
'de' => 14,
|
2021-05-10 00:10:37 +00:00
|
|
|
'en' => 100,
|
2021-08-09 18:08:33 +00:00
|
|
|
'eo' => 0,
|
2022-04-04 12:08:38 +00:00
|
|
|
'es' => 39,
|
2021-08-09 18:08:33 +00:00
|
|
|
'fil_PH' => 0,
|
2022-04-04 12:08:38 +00:00
|
|
|
'fr' => 10,
|
2021-08-09 18:08:33 +00:00
|
|
|
'gl_ES' => 0,
|
2021-05-10 00:10:37 +00:00
|
|
|
'id_ID' => 0,
|
2022-04-04 12:08:38 +00:00
|
|
|
'it' => 1,
|
2022-05-02 15:10:10 +00:00
|
|
|
'ja' => 33,
|
2022-03-02 09:13:50 +00:00
|
|
|
'ko' => 12,
|
2022-04-04 12:08:38 +00:00
|
|
|
'nb_NO' => 29,
|
2021-08-09 18:08:33 +00:00
|
|
|
'nl_NL' => 0,
|
2022-02-03 12:18:57 +00:00
|
|
|
'pl_PL' => 4,
|
2022-04-04 12:08:38 +00:00
|
|
|
'pt_BR' => 50,
|
2022-05-02 15:10:10 +00:00
|
|
|
'ro_RO' => 58,
|
|
|
|
'ru' => 30,
|
2022-04-04 12:08:38 +00:00
|
|
|
'tr_TR' => 13,
|
2022-05-02 15:10:10 +00:00
|
|
|
'uk' => 47,
|
|
|
|
'zh_CN' => 96,
|
2021-07-02 12:08:31 +00:00
|
|
|
'zh_HK' => 2,
|
2022-02-03 12:18:57 +00:00
|
|
|
'zh_TW' => 2
|
2021-05-10 00:10:37 +00:00
|
|
|
}.freeze
|
|
|
|
private_constant :TRANSLATION_LEVELS
|
2017-05-03 04:36:36 +00:00
|
|
|
|
2020-07-31 21:10:12 +00:00
|
|
|
def selectable_locales
|
2021-05-10 00:10:37 +00:00
|
|
|
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)
|
2020-07-31 21:10:12 +00:00
|
|
|
end
|
|
|
|
|
2017-05-03 04:36:36 +00:00
|
|
|
def available_locales
|
|
|
|
AVAILABLE_LANGUAGES.keys
|
|
|
|
end
|
2017-05-04 02:05:38 +00:00
|
|
|
|
2017-05-25 15:22:45 +00:00
|
|
|
def locale
|
|
|
|
FastGettext.locale
|
2017-05-04 02:05:38 +00:00
|
|
|
end
|
|
|
|
|
2017-05-25 15:22:45 +00:00
|
|
|
def locale=(locale_string)
|
|
|
|
requested_locale = locale_string || ::I18n.default_locale
|
|
|
|
new_locale = FastGettext.set_locale(requested_locale)
|
|
|
|
::I18n.locale = new_locale
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_default_locale
|
2017-05-04 23:44:19 +00:00
|
|
|
FastGettext.set_locale(::I18n.default_locale)
|
2017-05-04 02:05:38 +00:00
|
|
|
::I18n.locale = ::I18n.default_locale
|
|
|
|
end
|
2017-05-25 15:22:45 +00:00
|
|
|
|
|
|
|
def with_locale(locale_string)
|
|
|
|
original_locale = locale
|
|
|
|
|
|
|
|
self.locale = locale_string
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
self.locale = original_locale
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_user_locale(user, &block)
|
|
|
|
with_locale(user&.preferred_language, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_default_locale(&block)
|
|
|
|
with_locale(::I18n.default_locale, &block)
|
|
|
|
end
|
2017-04-13 04:23:02 +00:00
|
|
|
end
|
|
|
|
end
|