Class: Money::LocaleBackend::I18n

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

Constant Summary collapse

KEY_MAP =
{
  thousands_separator: :delimiter,
  decimal_mark: :separator,
  symbol: :unit
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeI18n

Returns a new instance of I18n.

Raises:


12
13
14
# File 'lib/money/locale_backend/i18n.rb', line 12

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

Instance Method Details

#lookup(key, _) ⇒ Object


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

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