Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Include the key in "missing interpolation argument" errors.

  • Loading branch information...
commit efd9f1c329539568e3adf1cb34fd8ac4e9ec85bb 1 parent 2553ed2
Henrik Nyh authored September 16, 2012
2  lib/i18n/backend/interpolation_compiler.rb
@@ -77,7 +77,7 @@ def nil_key(key)
77 77
         end
78 78
 
79 79
         def missing_key(key)
80  
-          "raise(MissingInterpolationArgument.new(#{key}, self))"
  80
+          "raise(MissingInterpolationArgument.new(#{key}, {}, self))"
81 81
         end
82 82
 
83 83
         def reserved_key(key)
8  lib/i18n/exceptions.rb
@@ -81,10 +81,10 @@ def initialize(entry, count)
81 81
   end
82 82
 
83 83
   class MissingInterpolationArgument < ArgumentError
84  
-    attr_reader :values, :string
85  
-    def initialize(values, string)
86  
-      @values, @string = values, string
87  
-      super "missing interpolation argument in #{string.inspect} (#{values.inspect} given)"
  84
+    attr_reader :key, :values, :string
  85
+    def initialize(key, values, string)
  86
+      @key, @values, @string = key, values, string
  87
+      super "missing interpolation argument #{key.inspect} in #{string.inspect} (#{values.inspect} given)"
88 88
     end
89 89
   end
90 90
 
2  lib/i18n/interpolate/ruby.rb
@@ -21,7 +21,7 @@ def interpolate_hash(string, values)
21 21
           '%'
22 22
         else
23 23
           key = ($1 || $2).to_sym
24  
-          value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
  24
+          value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(key, values, string))
25 25
           value = value.call(values) if value.respond_to?(:call)
26 26
           $3 ? sprintf("%#{$3}", value) : value
27 27
         end
4  test/i18n/exceptions_test.rb
@@ -54,14 +54,14 @@ def test_invalid_locale_stores_locale
54 54
   test "MissingInterpolationArgument stores key and string" do
55 55
     assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
56 56
     force_missing_interpolation_argument do |exception|
57  
-      # assert_equal :bar, exception.key
  57
+      assert_equal :bar, exception.key
58 58
       assert_equal "%{bar}", exception.string
59 59
     end
60 60
   end
61 61
 
62 62
   test "MissingInterpolationArgument message contains the missing and given arguments" do
63 63
     force_missing_interpolation_argument do |exception|
64  
-      assert_equal 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', exception.message
  64
+      assert_equal 'missing interpolation argument :bar in "%{bar}" ({:baz=>"baz"} given)', exception.message
65 65
     end
66 66
   end
67 67
 

0 notes on commit efd9f1c

Please sign in to comment.
Something went wrong with that request. Please try again.