Module: Gitlab::I18n

Extended by:
I18n
Included in:
I18n
Defined in:
lib/gitlab/i18n.rb,
lib/gitlab/i18n/po_linter.rb,
lib/gitlab/i18n/pluralization.rb,
lib/gitlab/i18n/metadata_entry.rb,
lib/gitlab/i18n/translation_entry.rb

Defined Under Namespace

Modules: Pluralization Classes: MetadataEntry, PoLinter, TranslationEntry

Constant Summary collapse

MINIMUM_TRANSLATION_LEVEL =

Languages with less then MINIMUM_TRANSLATION_LEVEL% of available translations will not be available in the UI. gitlab.com/gitlab-org/gitlab/-/issues/221012

2

Instance Method Summary collapse

Instance Method Details

#available_localesObject



84
85
86
# File 'lib/gitlab/i18n.rb', line 84

def available_locales
  AVAILABLE_LANGUAGES.keys
end

#localeObject



88
89
90
# File 'lib/gitlab/i18n.rb', line 88

def locale
  FastGettext.locale
end

#locale=(locale_string) ⇒ Object



92
93
94
95
96
# File 'lib/gitlab/i18n.rb', line 92

def locale=(locale_string)
  requested_locale = locale_string || ::I18n.default_locale
  new_locale = FastGettext.set_locale(requested_locale)
  ::I18n.locale = new_locale
end

#percentage_translated_for(code) ⇒ Object



80
81
82
# File 'lib/gitlab/i18n.rb', line 80

def percentage_translated_for(code)
  TRANSLATION_LEVELS.fetch(code, 0)
end

#selectable_locales(minimum_translation_level = MINIMUM_TRANSLATION_LEVEL) ⇒ Object



74
75
76
77
78
# File 'lib/gitlab/i18n.rb', line 74

def selectable_locales(minimum_translation_level = MINIMUM_TRANSLATION_LEVEL)
  AVAILABLE_LANGUAGES.reject do |code, _name|
    percentage_translated_for(code) < minimum_translation_level
  end
end

#setup(domain:, default_locale:) ⇒ Object



120
121
122
123
124
# File 'lib/gitlab/i18n.rb', line 120

def setup(domain:, default_locale:)
  custom_pluralization
  setup_repositories(domain)
  setup_default_locale(default_locale)
end

#use_default_localeObject



98
99
100
101
# File 'lib/gitlab/i18n.rb', line 98

def use_default_locale
  FastGettext.set_locale(::I18n.default_locale)
  ::I18n.locale = ::I18n.default_locale
end

#with_default_locale(&block) ⇒ Object



116
117
118
# File 'lib/gitlab/i18n.rb', line 116

def with_default_locale(&block)
  with_locale(::I18n.default_locale, &block)
end

#with_locale(locale_string) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/gitlab/i18n.rb', line 103

def with_locale(locale_string)
  original_locale = locale

  self.locale = locale_string
  yield
ensure
  self.locale = original_locale
end

#with_user_locale(user, &block) ⇒ Object



112
113
114
# File 'lib/gitlab/i18n.rb', line 112

def with_user_locale(user, &block)
  with_locale(user&.preferred_language, &block)
end