# Localize and lambdas

**URL:** <https://www.ruby-forum.com/t/localize-and-lambdas/186418>\
**Category:** Rails I18n\
**Created:** [April 6, 2010, 10:50pm UTC](https://www.ruby-forum.com/t/localize-and-lambdas/186418 "2010-04-06T22:50:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob-twf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@rob-twf](https://www.ruby-forum.com/u/rob-twf)\
**Post date:** [April 6, 2010, 10:50pm UTC](https://www.ruby-forum.com/t/localize-and-lambdas/186418/1 "2010-04-06T22:50:25Z")

</div>

Since localize was changed to go via translate rather than directly  
resolving, it seems lambdas no longer work. The problem being that the  
lambda is called in translate, which doesn’t have access to the object  
being localized.

Is this a bug? If it isn’t, what’s the suggested way of supporting  
lambdas in localization now?

A simple example, which works with 0.3.3 (as bundled with Rails 2.3.5)  
but breaks with 0.3.6:

{  
:en =\> {  
:date =\> {  
:formats =\> {  
:long\_ordinal =\> lambda { |date, options| “%B  
#{date.day.ordinalize}, %Y” }  
}  
}  
}

Thanks in advance,  
rob

---

<div class="post-metadata">

**Author:** ![rob-twf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@rob-twf](https://www.ruby-forum.com/u/rob-twf)\
**Post date:** [May 3, 2010, 7:34am UTC](https://www.ruby-forum.com/t/localize-and-lambdas/186418/2 "2010-05-03T07:34:08Z")

</div>

Hi Rob,

Some weeks ago I opened an issue about this in GitHub:

> <https://github.com/ruby-i18n/i18n/issues/14>
>
> I would like to understand when we can use translation with lambda.
> I thought th…e lambda should have a argument with the object to be translated.
> 
> For a instance, please checkout this gist: https://gist.github.com/528d924118bb70512fd6
> 
> For me, without the object the lambda usage doesn't make a lot of sense, or better, just when we use the options.

and today Jose Válim answered and asked me checkout this mailing  
list.

So, in test suite this feature was commented:  
[http://github.com/svenfuchs/i18n/blob/master/test/api/tests/localization/date.rb](http://github.com/svenfuchs/i18n/blob/master/test/api/tests/localization/date.rb)  
[http://github.com/svenfuchs/i18n/blob/master/test/api/tests/localization/time.rb](http://github.com/svenfuchs/i18n/blob/master/test/api/tests/localization/time.rb)  
this means the developers know this bug.

While I waited an answer from GitHub I got fixed this bug and I sent a  
pull request to Sven Funchs but didn’t get a answer yet.

José Valim, I sent a pull request again addressing you (too). Could  
you checkout it? Excuse me for not having sent a message in request, I  
sent the form of pull request without want, before fill the message.

Thanks,  
Lucas de Castro

---

<div class="post-metadata">

**Author:** ![rob-twf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@rob-twf](https://www.ruby-forum.com/u/rob-twf)\
**Post date:** [May 21, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/localize-and-lambdas/186418/3 "2010-05-21T16:16:11Z")

</div>

Thanks for the reply Lucas, looks like your fix has made it into the  
official code now too!

Rob

---

<div class="post-metadata">

**Author:** ![rob-twf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@rob-twf](https://www.ruby-forum.com/u/rob-twf)\
**Post date:** [May 21, 2010, 4:24pm UTC](https://www.ruby-forum.com/t/localize-and-lambdas/186418/4 "2010-05-21T16:24:58Z")

</div>

Yes Rob, it is there! 🙂

On Fri, May 21, 2010 at 11:15 AM, rob-twf  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > and today Jose VÃ¡lim answered and asked me checkout this mailing  
> > JosÃ© Valim, I sent a pull request again addressing you (too). Could
> > 
> > > but breaks with 0.3.6:  
> > > }  
> > > .  
> > > For more options, visit this group at  
> > > [http://groups.google.com/group/rails-i18n?hl=en](http://groups.google.com/group/rails-i18n?hl=en).

–  
Lucas
