<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -170,7 +170,8 @@ module I18n
         # interpolation).
         def interpolate(locale, string, values = {})
           return string unless string.is_a?(String) &amp;&amp; !values.empty?
-          string.gsub(INTERPOLATION_SYNTAX_PATTERN) do
+
+          s = string.gsub(INTERPOLATION_SYNTAX_PATTERN) do
             escaped, key = $1, $2.to_sym
             if escaped
               &quot;{{#{key}}}&quot;
@@ -179,12 +180,20 @@ module I18n
             else
               &quot;%{#{key}}&quot;
             end
-          end % values
+          end
+          values.each { |key, value| values[key] = value.call if interpolate_lambda?(value, s, key) }
+          s % values
 
         rescue KeyError =&gt; e
           raise MissingInterpolationArgument.new(values, string)
         end
 
+        # returns true when the given value responds to :call and the key is
+        # an interpolation placeholder in the given string
+        def interpolate_lambda?(object, string, key)
+          object.respond_to?(:call) &amp;&amp; string =~ /%\{#{key}\}|%\&lt;#{key}&gt;.*?\d*\.?\d*[bBdiouxXeEfgGcps]\}/
+        end
+
         # Loads a single translations file by delegating to #load_rb or
         # #load_yml depending on the file extension and directly merges the
         # data to the existing translations. Raises I18n::UnknownFileType</diff>
      <filename>lib/i18n/backend/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,6 +20,14 @@ module Tests
           assert_equal 'Hi !', interpolate(:default =&gt; 'Hi {{name}}!', :name =&gt; nil)
         end
 
+        def test_interpolation_given_a_lambda_as_a_value_it_calls_it_when_the_string_contains_the_key
+          assert_equal 'Hi David!', interpolate(:default =&gt; 'Hi {{name}}!', :name =&gt; lambda { 'David' })
+        end
+
+        def test_interpolation_given_a_lambda_as_a_value_it_does_not_call_it_when_the_string_does_not_contain_the_key
+          assert_nothing_raised { interpolate(:default =&gt; 'Hi!', :name =&gt; lambda { raise 'fail' }) }
+        end
+
         def test_interpolation_given_interpolation_values_but_missing_a_key_it_raises_a_missing_interpolation_argument_exception
           assert_raises(I18n::MissingInterpolationArgument) do
             interpolate(:default =&gt; '{{foo}}', :bar =&gt; 'bar')</diff>
      <filename>test/api/interpolation.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9be3d4a311b5bf583eec5d39986176cc40c112f2</id>
    </parent>
  </parents>
  <author>
    <name>Sven Fuchs</name>
    <email>svenfuchs@artweb-design.de</email>
  </author>
  <url>http://github.com/lawrencepit/i18n/commit/0e7546d49d861618d98efd04291614a78b793fdc</url>
  <id>0e7546d49d861618d98efd04291614a78b793fdc</id>
  <committed-date>2009-08-26T08:47:03-07:00</committed-date>
  <authored-date>2009-08-26T08:47:03-07:00</authored-date>
  <message>Allow to use lambdas as interpolation values.

E.g. I18n.t(:default =&gt; 'Hi {{name}}!', :name =&gt; lambda { 'David' }) would now return &quot;Hi David!&quot;. 

This is particularly useful when client code (such as ActiveRecord Validations) provides a couple of possible interpolation values without knowing which of them will be actually used by translators. Expensive lookups of such values can now be wrapped into a lambda and passed as interpolation values.</message>
  <tree>08e3c0f7a5f563350ed0a181f8b1740712b70d3f</tree>
  <committer>
    <name>Sven Fuchs</name>
    <email>svenfuchs@artweb-design.de</email>
  </committer>
</commit>
