2017-04-13 00:23:02 -04:00
|
|
|
module Gitlab
|
|
|
|
module I18n
|
2017-05-03 00:36:36 -04:00
|
|
|
extend self
|
|
|
|
|
2017-04-20 00:19:24 -04:00
|
|
|
AVAILABLE_LANGUAGES = {
|
2017-05-04 19:44:19 -04:00
|
|
|
'en' => 'English',
|
|
|
|
'es' => 'Español',
|
|
|
|
'de' => 'Deutsch'
|
2017-04-20 00:19:24 -04:00
|
|
|
}.freeze
|
2017-05-03 00:36:36 -04:00
|
|
|
|
|
|
|
def available_locales
|
|
|
|
AVAILABLE_LANGUAGES.keys
|
|
|
|
end
|
2017-05-03 22:05:38 -04:00
|
|
|
|
|
|
|
def set_locale(current_user)
|
|
|
|
requested_locale = current_user&.preferred_language || ::I18n.default_locale
|
|
|
|
locale = FastGettext.set_locale(requested_locale)
|
|
|
|
::I18n.locale = locale
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_locale
|
2017-05-04 19:44:19 -04:00
|
|
|
FastGettext.set_locale(::I18n.default_locale)
|
2017-05-03 22:05:38 -04:00
|
|
|
::I18n.locale = ::I18n.default_locale
|
|
|
|
end
|
2017-04-13 00:23:02 -04:00
|
|
|
end
|
|
|
|
end
|