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 = {
|
2017-05-04 23:44:19 +00:00
|
|
|
'en' => 'English',
|
|
|
|
'es' => 'Español',
|
2017-05-23 12:31:09 +00:00
|
|
|
'de' => 'Deutsch',
|
2017-06-15 21:08:37 +00:00
|
|
|
'fr' => 'Français',
|
2017-07-24 07:33:09 +00:00
|
|
|
'pt_BR' => 'Português (Brasil)',
|
2017-05-27 03:34:55 +00:00
|
|
|
'zh_CN' => '简体中文',
|
2017-07-24 07:33:09 +00:00
|
|
|
'zh_HK' => '繁體中文 (香港)',
|
|
|
|
'zh_TW' => '繁體中文 (臺灣)',
|
2017-06-26 02:15:44 +00:00
|
|
|
'bg' => 'български',
|
2017-07-10 02:12:59 +00:00
|
|
|
'ru' => 'Русский',
|
2017-06-30 01:58:47 +00:00
|
|
|
'eo' => 'Esperanto',
|
2017-07-19 10:47:41 +00:00
|
|
|
'it' => 'Italiano',
|
2017-07-10 02:33:19 +00:00
|
|
|
'uk' => 'Українська',
|
2017-08-07 09:19:41 +00:00
|
|
|
'ja' => '日本語',
|
2017-09-18 15:13:47 +00:00
|
|
|
'ko' => '한국어',
|
2018-03-05 14:59:12 +00:00
|
|
|
'nl_NL' => 'Nederlands',
|
|
|
|
'tr_TR' => 'Türkçe',
|
|
|
|
'id_ID' => 'Bahasa Indonesia',
|
|
|
|
'fil_PH' => 'Filipino'
|
2017-04-20 04:19:24 +00:00
|
|
|
}.freeze
|
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
|