upgrade Rails localization from SimpleLocalization to Rails 2.3.2/simple_loc_compat

Posted on March 30, 2009. Filed under: Ruby on Rails, work | Tags: , , , , , , |

[i] At work, currently I’m porting apps from Rails about 2.0.2 to 2.3.2. One of the issues I stumbled upon more but once is how to deal with Rails 2.3.2’s l() method.

As far as I got it until now, in Rails 2.0.2 a SimpleLocalization module was kind of popular to get localization done. Also (still under the presumption I got it right), there was a method l() to get the localized version of a string output. In Rails 2.3.2, now, there is a l() method also, also for localization. Unfortunately, SimpleLocalization’s l() and Rails 2.3.2’s l() aren’t compatible.

To fix this, there is a simple_loc_compat.rb piece of code — the (modified) ArkanisDevelopmentCompat module. That (modified) module evades collosion with the l() method naming by providing a ll() method instead (two Ls now).

If you want to make everything work again, simplest way is to overwrite Rails 2.3.2’s native l() by a wrapper of ll():

def l(*args)
  ll(*args)
end

In other words: Rails 2.3.2 has an l() method for localization. That one is incompatible with SimpleLocalization’s one. So, to avoid the need to rewrite every occurence of l() in your code, install the simple_loc_compat plugin. That one provides an ll() method which is compatible to the old (SimpleLocalization’s) l(). To avoid the need to replace l() calls by ll() ones, we write a wrapper for ll() which, at the same time, disables the Rails 2.3.2’s l() method. (The method shown above is that wrapper.)

Depending on whether only your views make use of l() or some controller also, say for a localized flash message, you’d put the wrapper into a helper or directly into the ApplicationController. If you put the wrapper into the controller, adding a helper_method :l to the controller, too, makes the l() method available not only for the controller but also to the the views.

However, the structure of the localization YAML files have changed and may still interfere. However, by the way described above, you skip rewriting every occurence of an l() method that had the SimpleLocalization’s l() method in mind.
 

_____
A ton of thanks go out to DerGuteMoritz for helping me to get this straight.

Make a Comment

Make a Comment: ( None so far )

blockquote and a tags work here.

Liked it here?
Why not try sites on the blogroll...