gitlab-org--gitlab-foss/lib/gitlab/i18n.rb

65 lines
1.5 KiB
Ruby
Raw Normal View History

module Gitlab
module I18n
extend self
AVAILABLE_LANGUAGES = {
'en' => 'English',
'es' => 'Español',
2017-05-23 08:31:09 -04:00
'de' => 'Deutsch',
'fr' => 'Français',
'pt_BR' => 'Português (Brasil)',
2017-05-26 23:34:55 -04:00
'zh_CN' => '简体中文',
'zh_HK' => '繁體中文 (香港)',
'zh_TW' => '繁體中文 (臺灣)',
'bg' => 'български',
2017-07-09 22:12:59 -04:00
'ru' => 'Русский',
'eo' => 'Esperanto',
2017-07-19 06:47:41 -04:00
'it' => 'Italiano',
2017-07-09 22:33:19 -04:00
'uk' => 'Українська',
2017-08-07 05:19:41 -04:00
'ja' => '日本語',
2017-09-18 11:13:47 -04:00
'ko' => '한국어',
'nl_NL' => 'Nederlands',
'tr_TR' => 'Türkçe',
'id_ID' => 'Bahasa Indonesia',
'fil_PH' => 'Filipino',
'pl_PL' => 'Polski'
}.freeze
def available_locales
AVAILABLE_LANGUAGES.keys
end
def locale
FastGettext.locale
end
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
FastGettext.set_locale(::I18n.default_locale)
::I18n.locale = ::I18n.default_locale
end
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
end
end