Module: I18n::MissingTranslation::Base
- Included in:
- I18n::MissingTranslation, I18n::MissingTranslationData
- Defined in:
- lib/i18n/exceptions.rb
Constant Summary collapse
- PERMITTED_KEYS =
[:scope, :default].freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #initialize(locale, key, options = EMPTY_HASH) ⇒ Object
- #keys ⇒ Object
- #message ⇒ Object (also: #to_s)
- #normalized_option(key) ⇒ Object
- #to_exception ⇒ Object
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
50 51 52 |
# File 'lib/i18n/exceptions.rb', line 50 def key @key end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
50 51 52 |
# File 'lib/i18n/exceptions.rb', line 50 def locale @locale end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
50 51 52 |
# File 'lib/i18n/exceptions.rb', line 50 def end |
Instance Method Details
#initialize(locale, key, options = EMPTY_HASH) ⇒ Object
52 53 54 55 |
# File 'lib/i18n/exceptions.rb', line 52 def initialize(locale, key, = EMPTY_HASH) @key, @locale, = key, locale, .slice(*PERMITTED_KEYS) .each { |k, v| self.[k] = v.inspect if v.is_a?(Proc) } end |
#keys ⇒ Object
57 58 59 60 61 |
# File 'lib/i18n/exceptions.rb', line 57 def keys @keys ||= I18n.normalize_keys(locale, key, [:scope]).tap do |keys| keys << 'no key' if keys.size < 2 end end |
#message ⇒ Object Also known as: to_s
63 64 65 66 67 68 69 70 |
# File 'lib/i18n/exceptions.rb', line 63 def if (default = [:default]).is_a?(Array) && default.any? = ([key, *default]).map { |k| normalized_option(k).prepend('- ') }.join("\n") "Translation missing. Options considered were:\n#{other_options}" else "Translation missing: #{keys.join('.')}" end end |
#normalized_option(key) ⇒ Object
72 73 74 |
# File 'lib/i18n/exceptions.rb', line 72 def normalized_option(key) I18n.normalize_keys(locale, key, [:scope]).join('.') end |
#to_exception ⇒ Object
78 79 80 |
# File 'lib/i18n/exceptions.rb', line 78 def to_exception MissingTranslationData.new(locale, key, ) end |