Exception: I18n::MissingTranslationData

Inherits:
ArgumentError
  • Object
show all
Defined in:
lib/i18n/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale, key, opts = nil) ⇒ MissingTranslationData

Returns a new instance of MissingTranslationData.



39
40
41
42
43
# File 'lib/i18n/exceptions.rb', line 39

def initialize(locale, key, opts = nil)
  @key, @locale, @options = key, locale, opts.dup || {}
  options.each { |k, v| options[k] = v.inspect if v.is_a?(Proc) }
  super "translation missing: #{keys.join('.')}"
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



37
38
39
# File 'lib/i18n/exceptions.rb', line 37

def key
  @key
end

#localeObject (readonly)

Returns the value of attribute locale.



37
38
39
# File 'lib/i18n/exceptions.rb', line 37

def locale
  @locale
end

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/i18n/exceptions.rb', line 37

def options
  @options
end

Instance Method Details

#html_messageObject



45
46
47
48
# File 'lib/i18n/exceptions.rb', line 45

def html_message
  key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
  %(<span class="translation_missing" title="translation missing: #{keys.join('.')}">#{key}</span>)
end

#keysObject



50
51
52
53
54
# File 'lib/i18n/exceptions.rb', line 50

def keys
  @keys ||= I18n.normalize_keys(locale, key, options[:scope]).tap do |keys|
    keys << 'no key' if keys.size < 2
  end
end