debian-mirror-gitlab/lib/gitlab/i18n.rb

87 lines
2.3 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module I18n
extend self
2020-10-24 23:57:45 +05:30
# 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
2017-08-17 22:00:37 +05:30
AVAILABLE_LANGUAGES = {
2020-05-24 23:13:21 +05:30
'bg' => 'Bulgarian - български',
'cs_CZ' => 'Czech - čeština',
'de' => 'German - Deutsch',
2017-08-17 22:00:37 +05:30
'en' => 'English',
2020-05-24 23:13:21 +05:30
'eo' => 'Esperanto - esperanto',
'es' => 'Spanish - español',
2018-11-08 19:23:39 +05:30
'fil_PH' => 'Filipino',
2020-05-24 23:13:21 +05:30
'fr' => 'French - français',
'gl_ES' => 'Galician - galego',
'id_ID' => 'Indonesian - Bahasa Indonesia',
'it' => 'Italian - italiano',
'ja' => 'Japanese - 日本語',
'ko' => 'Korean - 한국어',
'nl_NL' => 'Dutch - Nederlands',
'pl_PL' => 'Polish - polski',
'pt_BR' => 'Portuguese (Brazil) - português (Brasil)',
'ru' => 'Russian - Русский',
'tr_TR' => 'Turkish - Türkçe',
'uk' => 'Ukrainian - українська',
'zh_CN' => 'Chinese, Simplified - 简体中文',
'zh_HK' => 'Chinese, Traditional (Hong Kong) - 繁體中文 (香港)',
'zh_TW' => 'Chinese, Traditional (Taiwan) - 繁體中文 (台灣)'
2017-08-17 22:00:37 +05:30
}.freeze
2020-10-24 23:57:45 +05:30
def selectable_locales
AVAILABLE_LANGUAGES.reject { |key, _value| NOT_AVAILABLE_IN_UI.include? key }
end
2017-08-17 22:00:37 +05:30
def available_locales
AVAILABLE_LANGUAGES.keys
end
2017-09-10 17:25:29 +05:30
def locale
FastGettext.locale
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
FastGettext.set_locale(::I18n.default_locale)
::I18n.locale = ::I18n.default_locale
end
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
end
end