Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

I18n.translate strange behavior with the << operator

#4371

Run script/console in a Rails application:

x = I18n.translate 'foo' => "Foo text"

x << ' more text added on the fly' => "Foo text more text added on the fly"

I18n.translate 'foo' # OhMy!! the added text is now in the translation cache! => "Teixo more text added on the fly"

This not occurs if use the += operator (x += 'some text'), but the problem is that this behavior is unespected, and quite hard to detect.
One solution may be to clone the returned String in the I18n.translate implementation.

Reported by Mario · April 12th, 2010 @ 04:56 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Mario
    Mario

    Sorry, the previous post is not correctly formatted.
    Repeat code:

      x = I18n.translate :foo
      #=> "Foo Text"
    
      x << ' plus more text added on the fly'
      #=> "Foo Text plus more text added on the fly"
      
      # OhMy!! The added text is now in the translation cache!
      I18n.translate :foo
      #=> "Foo Text plus more text added on the fly"
    

    Using the << operator, in each request the same text is appended, and is hard to discover the reason.

    April 12th, 2010 @ 05:03 PM

  2. thedarkone
  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to resolved

    Yes and it's an I18n thing

    April 12th, 2010 @ 11:21 PM