summaryrefslogtreecommitdiff
path: root/lib/gitlab/i18n.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/i18n.rb')
-rw-r--r--lib/gitlab/i18n.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/i18n.rb b/lib/gitlab/i18n.rb
new file mode 100644
index 00000000000..3411516319f
--- /dev/null
+++ b/lib/gitlab/i18n.rb
@@ -0,0 +1,26 @@
+module Gitlab
+ module I18n
+ extend self
+
+ AVAILABLE_LANGUAGES = {
+ 'en' => 'English',
+ 'es' => 'EspaƱol',
+ 'de' => 'Deutsch'
+ }.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