2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module I18n
|
|
|
|
extend self
|
|
|
|
|
|
|
|
AVAILABLE_LANGUAGES = {
|
|
|
|
'en' => 'English',
|
|
|
|
'es' => 'Español',
|
2017-09-10 17:25:29 +05:30
|
|
|
'de' => 'Deutsch',
|
|
|
|
'fr' => 'Français',
|
|
|
|
'pt_BR' => 'Português (Brasil)',
|
|
|
|
'zh_CN' => '简体中文',
|
|
|
|
'zh_HK' => '繁體中文 (香港)',
|
|
|
|
'zh_TW' => '繁體中文 (臺灣)',
|
|
|
|
'bg' => 'български',
|
|
|
|
'ru' => 'Русский',
|
|
|
|
'eo' => 'Esperanto',
|
|
|
|
'it' => 'Italiano',
|
|
|
|
'uk' => 'Українська',
|
|
|
|
'ja' => '日本語',
|
2018-03-17 18:26:18 +05:30
|
|
|
'ko' => '한국어',
|
2018-03-27 19:54:05 +05:30
|
|
|
'nl_NL' => 'Nederlands',
|
|
|
|
'tr_TR' => 'Türkçe',
|
|
|
|
'id_ID' => 'Bahasa Indonesia',
|
|
|
|
'fil_PH' => 'Filipino'
|
2017-08-17 22:00:37 +05:30
|
|
|
}.freeze
|
|
|
|
|
|
|
|
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
|