2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-13 00:23:02 -04:00
|
|
|
module Gitlab
|
|
|
|
module I18n
|
2017-05-03 00:36:36 -04:00
|
|
|
extend self
|
|
|
|
|
2017-04-20 00:19:24 -04:00
|
|
|
AVAILABLE_LANGUAGES = {
|
2020-05-04 23:09:46 -04:00
|
|
|
'bg' => 'Bulgarian - български',
|
|
|
|
'cs_CZ' => 'Czech - čeština',
|
2021-08-31 08:11:07 -04:00
|
|
|
'da_DK' => 'Danish - dansk',
|
2020-05-04 23:09:46 -04:00
|
|
|
'de' => 'German - Deutsch',
|
2017-05-04 19:44:19 -04:00
|
|
|
'en' => 'English',
|
2020-05-04 23:09:46 -04:00
|
|
|
'eo' => 'Esperanto - esperanto',
|
|
|
|
'es' => 'Spanish - español',
|
2018-05-14 09:20:38 -04:00
|
|
|
'fil_PH' => 'Filipino',
|
2020-05-04 23:09:46 -04:00
|
|
|
'fr' => 'French - français',
|
|
|
|
'gl_ES' => 'Galician - galego',
|
|
|
|
'id_ID' => 'Indonesian - Bahasa Indonesia',
|
|
|
|
'it' => 'Italian - italiano',
|
|
|
|
'ja' => 'Japanese - 日本語',
|
|
|
|
'ko' => 'Korean - 한국어',
|
2021-08-31 08:11:07 -04:00
|
|
|
'nb_NO' => 'Norwegian (Bokmål) - norsk (bokmål)',
|
2020-05-04 23:09:46 -04:00
|
|
|
'nl_NL' => 'Dutch - Nederlands',
|
|
|
|
'pl_PL' => 'Polish - polski',
|
|
|
|
'pt_BR' => 'Portuguese (Brazil) - português (Brasil)',
|
2021-08-31 08:11:07 -04:00
|
|
|
'ro_RO' => 'Romanian - română',
|
|
|
|
'ru' => 'Russian - русский',
|
2022-07-18 05:08:30 -04:00
|
|
|
'si_LK' => 'Sinhalese - සිංහල',
|
2020-05-04 23:09:46 -04: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 00:19:24 -04:00
|
|
|
}.freeze
|
2021-05-09 20:10:37 -04: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 14:08:33 -04:00
|
|
|
'bg' => 0,
|
2021-09-02 08:11:03 -04:00
|
|
|
'cs_CZ' => 0,
|
2022-10-13 05:37:59 -04:00
|
|
|
'da_DK' => 37,
|
2022-08-16 05:12:32 -04:00
|
|
|
'de' => 17,
|
2021-05-09 20:10:37 -04:00
|
|
|
'en' => 100,
|
2021-08-09 14:08:33 -04:00
|
|
|
'eo' => 0,
|
2022-10-13 05:37:59 -04:00
|
|
|
'es' => 36,
|
2021-08-09 14:08:33 -04:00
|
|
|
'fil_PH' => 0,
|
2022-10-13 05:37:59 -04:00
|
|
|
'fr' => 72,
|
2021-08-09 14:08:33 -04:00
|
|
|
'gl_ES' => 0,
|
2021-05-09 20:10:37 -04:00
|
|
|
'id_ID' => 0,
|
2022-04-04 08:08:38 -04:00
|
|
|
'it' => 1,
|
2022-09-12 11:14:03 -04:00
|
|
|
'ja' => 31,
|
2022-10-13 05:37:59 -04:00
|
|
|
'ko' => 20,
|
|
|
|
'nb_NO' => 25,
|
2021-08-09 14:08:33 -04:00
|
|
|
'nl_NL' => 0,
|
2022-10-13 05:37:59 -04:00
|
|
|
'pl_PL' => 3,
|
|
|
|
'pt_BR' => 57,
|
2022-09-12 11:14:03 -04:00
|
|
|
'ro_RO' => 99,
|
2022-10-13 05:37:59 -04:00
|
|
|
'ru' => 26,
|
|
|
|
'si_LK' => 11,
|
2022-09-12 11:14:03 -04:00
|
|
|
'tr_TR' => 11,
|
2022-10-13 05:37:59 -04:00
|
|
|
'uk' => 49,
|
|
|
|
'zh_CN' => 98,
|
2022-08-16 05:12:32 -04:00
|
|
|
'zh_HK' => 1,
|
2022-09-12 11:14:03 -04:00
|
|
|
'zh_TW' => 99
|
2021-05-09 20:10:37 -04:00
|
|
|
}.freeze
|
|
|
|
private_constant :TRANSLATION_LEVELS
|
2017-05-03 00:36:36 -04:00
|
|
|
|
2020-07-31 17:10:12 -04:00
|
|
|
def selectable_locales
|
2021-05-09 20:10:37 -04: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 17:10:12 -04:00
|
|
|
end
|
|
|
|
|
2017-05-03 00:36:36 -04:00
|
|
|
def available_locales
|
|
|
|
AVAILABLE_LANGUAGES.keys
|
|
|
|
end
|
2017-05-03 22:05:38 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
def locale
|
|
|
|
FastGettext.locale
|
2017-05-03 22:05:38 -04:00
|
|
|
end
|
|
|
|
|
2017-05-25 11:22:45 -04: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 19:44:19 -04:00
|
|
|
FastGettext.set_locale(::I18n.default_locale)
|
2017-05-03 22:05:38 -04:00
|
|
|
::I18n.locale = ::I18n.default_locale
|
|
|
|
end
|
2017-05-25 11:22:45 -04: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 00:23:02 -04:00
|
|
|
end
|
|
|
|
end
|