# I18n.with\_options bloc executed TWICE

**URL:** <https://www.ruby-forum.com/t/i18n-with-options-bloc-executed-twice/195863>\
**Category:** Rails\
**Created:** [October 1, 2010, 2:07pm UTC](https://www.ruby-forum.com/t/i18n-with-options-bloc-executed-twice/195863 "2010-10-01T14:07:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [October 1, 2010, 2:07pm UTC](https://www.ruby-forum.com/t/i18n-with-options-bloc-executed-twice/195863/1 "2010-10-01T14:07:02Z")

</div>

Hi, to avoid putting the whole locale scope on every I18n.t call I’m  
trying to use a scope, as stated in the doc  
([Active Support Core Extensions — Ruby on Rails Guides](http://guides.rubyonrails.org/active_support_core_extensions.html#with_options))

I tried with

\<%= I18n.with\_options :locale =\> :en, :scope =\> ‘portal.visitor\_menu’ do  
|i18n|%\>  
Try \<%= i18n.t :fav\_songs %\>  
\<% end %\>

But it produce  
Try favorite song  
Try favorite song

I mean, the bloc is executed TWICE. The same code exercised under the  
rails console is executed only ONCE.

Anybody have an idea of this strange phenomenom ?

Thanks

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [October 1, 2010, 2:27pm UTC](https://www.ruby-forum.com/t/i18n-with-options-bloc-executed-twice/195863/2 "2010-10-01T14:27:39Z")

</div>

On Oct 1, 1:07 pm, Bob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But it produce  
> Try favorite song  
> Try favorite song
> 
> I mean, the bloc is executed TWICE. The same code exercised under the  
> rails console is executed only ONCE.
> 
> Anybody have an idea of this strange phenomenom ?

You probably want \<% for the first tag. Right now the call to i18n.t  
is outputting text, and the call to with\_options is also a \<%= so will  
output whatever the result of that evaluation is

Fred
