Class: I18n::Hygiene::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/hygiene/wrapper.rb

Overview

Utility class for interacting with i18n definitions. This is not intended to be used in production code - it’s focus is on making the i18n data easily enumerable and queryable.

Instance Method Summary collapse

Constructor Details

#initialize(exclude_keys: [], exclude_scopes: [], locales: ::I18n.available_locales) ⇒ Wrapper

Returns a new instance of Wrapper.



11
12
13
14
15
# File 'lib/i18n/hygiene/wrapper.rb', line 11

def initialize(exclude_keys: [], exclude_scopes: [], locales: ::I18n.available_locales)
  @locales = locales
  @exclude_keys = exclude_keys
  @exclude_scopes = exclude_scopes
end

Instance Method Details

#key_found?(locale, key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/i18n/hygiene/wrapper.rb', line 29

def key_found?(locale, key)
  I18n.with_locale(locale) do
    I18n.exists?(key)
  end
end

#keys_to_check(locale) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/i18n/hygiene/wrapper.rb', line 17

def keys_to_check(locale)
  I18n::Hygiene::LocaleTranslations.new(
    translations: translations[locale],
    exclude_keys: exclude_keys,
    exclude_scopes: exclude_scopes
  ).keys_to_check
end

#localesObject



25
26
27
# File 'lib/i18n/hygiene/wrapper.rb', line 25

def locales
  @locales
end

#value(locale, key) ⇒ Object



35
36
37
38
39
# File 'lib/i18n/hygiene/wrapper.rb', line 35

def value(locale, key)
  I18n.with_locale(locale) do
    I18n.t(key, resolve: false)
  end
end