Class: Money::LocaleBackend::I18n

Inherits:
Base
  • Object
show all
Defined in:
lib/money/locale_backend/i18n.rb,
sig/lib/money/locale_backend/i18n.rbs

Constant Summary collapse

KEY_MAP =

Returns:

  • (Hash[Symbol, Symbol])
{
  thousands_separator: :delimiter,
  decimal_mark: :separator,
  symbol: :unit,
  format: :format,
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeI18n

Returns a new instance of I18n.

Raises:



15
16
17
18
19
# File 'lib/money/locale_backend/i18n.rb', line 15

def initialize
  raise NotSupported, "I18n not found" unless defined?(::I18n)

  super
end

Instance Method Details

#lookup(key, _) ⇒ Object

Parameters:

  • key (Symbol)
  • _ (Object)

Returns:

  • (Object)


21
22
23
24
25
26
27
# File 'lib/money/locale_backend/i18n.rb', line 21

def lookup(key, _)
  i18n_key = KEY_MAP[key]

  ::I18n.t i18n_key, scope: "number.currency.format", raise: true
rescue ::I18n::MissingTranslationData
  ::I18n.t i18n_key, scope: "number.format", default: nil
end