Class: Govspeak::TranslationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govspeak/translation_helper.rb

Class Method Summary collapse

Class Method Details

.supported_localesObject



18
19
20
21
22
23
24
25
26
# File 'lib/govspeak/translation_helper.rb', line 18

def self.supported_locales
  I18n.available_locales.map do |locale|
    {
      code: locale,
      english_name: I18n.t("english_name", locale:),
      native_name: I18n.t("native_name", locale:),
    }
  end
end

.t_with_fallback(key, **options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/govspeak/translation_helper.rb', line 3

def self.t_with_fallback(key, **options)
  if I18n.available_locales.none?(options[:locale]&.to_sym)
    options[:locale] = I18n.default_locale
  end

  if options[:locale] != I18n.default_locale
    options[:default] = I18n.t(
      key,
      **options.merge(locale: I18n.default_locale),
    )
  end

  I18n.t(key, **options)
end