gitlab-org--gitlab-foss/lib/gitlab/i18n.rb
Douwe Maan e50c31abc0 Merge branch '33383_add_bulgarian_translation_of_cycle_analytics_page' into 'master'
Add bulgarian translation of Cycle Analytics Page to I18N

Closes #33383

See merge request !11958
2017-06-08 14:49:35 +00:00

52 lines
1.1 KiB
Ruby

module Gitlab
module I18n
extend self
AVAILABLE_LANGUAGES = {
'en' => 'English',
'es' => 'Español',
'de' => 'Deutsch',
'pt_BR' => 'Português(Brasil)',
'zh_CN' => '简体中文',
'zh_HK' => '繁體中文(香港)',
'zh_TW' => '繁體中文(臺灣)',
'bg' => 'български'
}.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