summaryrefslogtreecommitdiff
path: root/lib/gitlab/i18n.rb
blob: edbe9bb11d16d9d8390c2e1f9e64495d0cf41eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding: utf-8
module Gitlab
  module I18n
    extend self

    AVAILABLE_LANGUAGES = {
      'en' => 'English',
      'es' => 'Español',
      'de' => 'Deutsch',
      'zh_CN' => '简体中文'
    }.freeze

    def available_locales
      AVAILABLE_LANGUAGES.keys
    end

    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
      FastGettext.set_locale(::I18n.default_locale)
      ::I18n.locale = ::I18n.default_locale
    end
  end
end