Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Include the key in "missing interpolation argument" errors.

  • Loading branch information...
commit efd9f1c329539568e3adf1cb34fd8ac4e9ec85bb 1 parent 2553ed2
@henrik henrik authored
View
2  lib/i18n/backend/interpolation_compiler.rb
@@ -77,7 +77,7 @@ def nil_key(key)
end
def missing_key(key)
- "raise(MissingInterpolationArgument.new(#{key}, self))"
+ "raise(MissingInterpolationArgument.new(#{key}, {}, self))"
end
def reserved_key(key)
View
8 lib/i18n/exceptions.rb
@@ -81,10 +81,10 @@ def initialize(entry, count)
end
class MissingInterpolationArgument < ArgumentError
- attr_reader :values, :string
- def initialize(values, string)
- @values, @string = values, string
- super "missing interpolation argument in #{string.inspect} (#{values.inspect} given)"
+ attr_reader :key, :values, :string
+ def initialize(key, values, string)
+ @key, @values, @string = key, values, string
+ super "missing interpolation argument #{key.inspect} in #{string.inspect} (#{values.inspect} given)"
end
end
View
2  lib/i18n/interpolate/ruby.rb
@@ -21,7 +21,7 @@ def interpolate_hash(string, values)
'%'
else
key = ($1 || $2).to_sym
- value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
+ value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(key, values, string))
value = value.call(values) if value.respond_to?(:call)
$3 ? sprintf("%#{$3}", value) : value
end
View
4 test/i18n/exceptions_test.rb
@@ -54,14 +54,14 @@ def test_invalid_locale_stores_locale
test "MissingInterpolationArgument stores key and string" do
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
force_missing_interpolation_argument do |exception|
- # assert_equal :bar, exception.key
+ assert_equal :bar, exception.key
assert_equal "%{bar}", exception.string
end
end
test "MissingInterpolationArgument message contains the missing and given arguments" do
force_missing_interpolation_argument do |exception|
- assert_equal 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', exception.message
+ assert_equal 'missing interpolation argument :bar in "%{bar}" ({:baz=>"baz"} given)', exception.message
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.