module Mova::I18nBridge::Translator
Public Instance Methods
default(locales, keys, options)
click to toggle source
# File lib/mova-i18n/bridge.rb, line 6 def default(locales, keys, options) origin_locale = locales.first origin_key = keys.first if options[:raise] raise I18n::MissingTranslationData.new(origin_locale, origin_key, options) end if options[:throw] throw :exception, I18n::MissingTranslation.new(origin_locale, origin_key, options) end key_with_locale = Mova::Scope.join(origin_locale, origin_key) "missing translation: #{key_with_locale}" end
put(translations)
click to toggle source
Calls superclass method
# File lib/mova-i18n/bridge.rb, line 22 def put(translations) super put_exact_translation(translations, "i18n.transliterate.rule") put_exact_translation(translations, "number.format") put_exact_translation(translations, "number.currency.format") put_exact_translation(translations, "number.human.format") put_exact_translation(translations, "number.human.decimal_units.units") put_exact_translation(translations, "number.percentage.format") put_exact_translation(translations, "number.precision.format") end
put_exact_translation(translations, key)
click to toggle source
Stores exact value because {Mova::Translator#put} flattens hashes before writing to the storage, while ‘I18n.transliterate` and Rails localization helpers rely on ability of storing hashes as is.
# File lib/mova-i18n/bridge.rb, line 36 def put_exact_translation(translations, key) scope_path = Mova::Scope.split(key).map &:to_sym locales = translations.keys locales.each do |locale| full_path = [locale] + scope_path translation = full_path.inject(translations) do |memo, scope| memo[scope] || {} end unless translation == {} key_with_locale = Mova::Scope.join(full_path) storage.write(key_with_locale, translation) end end end