From 292339641abb833272d962379ce2bcbad89a0d78 Mon Sep 17 00:00:00 2001 From: lulalala Date: Thu, 9 Nov 2017 22:55:52 +0800 Subject: [PATCH 1/2] Fix lambda document example --- lib/i18n.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index 297a6255..d79b661e 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -140,7 +140,7 @@ def reload! # called and passed the key and options. # # E.g. assuming the key :salutation resolves to: - # lambda { |key, options| options[:gender] == 'm' ? "Mr. %{options[:name]}" : "Mrs. %{options[:name]}" } + # lambda { |key, options| options[:gender] == 'm' ? "Mr. #{options[:name]}" : "Mrs. #{options[:name]}" } # # Then I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith". # From 0aca0666a304983d145efb764c39a6952af7664a Mon Sep 17 00:00:00 2001 From: lulalala Date: Thu, 9 Nov 2017 23:00:50 +0800 Subject: [PATCH 2/2] Document about lambda return value also being interpolated --- lib/i18n.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/i18n.rb b/lib/i18n.rb index d79b661e..c3d97367 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -144,6 +144,10 @@ def reload! # # Then I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith". # + # Note that the string returned by lambda will go through string interpolation too, + # so the following lambda would give the same result: + # lambda { |key, options| options[:gender] == 'm' ? "Mr. %{name}" : "Mrs. %{name}" } + # # It is recommended to use/implement lambdas in an "idempotent" way. E.g. when # a cache layer is put in front of I18n.translate it will generate a cache key # from the argument values passed to #translate. Therefor your lambdas should