lib/i18n/exceptions.rb in i18n-1.13.0 vs lib/i18n/exceptions.rb in i18n-1.14.0

- old
+ new

@@ -45,11 +45,11 @@ end end class MissingTranslation < ArgumentError module Base - PERMITTED_KEYS = [:scope].freeze + PERMITTED_KEYS = [:scope, :default].freeze attr_reader :locale, :key, :options def initialize(locale, key, options = EMPTY_HASH) @key, @locale, @options = key, locale, options.slice(*PERMITTED_KEYS) @@ -61,11 +61,21 @@ keys << 'no key' if keys.size < 2 end end def message - "translation missing: #{keys.join('.')}" + if options[:default].is_a?(Array) + other_options = ([key, *options[:default]]).map { |k| normalized_option(k).prepend('- ') }.join("\n") + "Translation missing. Options considered were:\n#{other_options}" + else + "Translation missing: #{keys.join('.')}" + end end + + def normalized_option(key) + I18n.normalize_keys(locale, key, options[:scope]).join('.') + end + alias :to_s :message def to_exception MissingTranslationData.new(locale, key, options) end