Rails/Globalize tip
- Published July 17th, 2008 in Tips & Tricks, Ruby
I'm absolutely burdened in work so there's no time for blogging or whatever might refrain me from producing (few exceptions apply — am I becoming a workaholic? nevermind the rhetoric question, I've always been one). But this tip is quick and very interesting.
If you're using the i18n/l13n Globalize plugin for your Ruby on Rails projects and you need to escape something from being translated in the middle of a sentence, you do not need to split it and then concatenate it as follows:
-
"to be translated ".t + user.name + " more to be translated".t
You can simply use Ruby's sugar candy to the string format function.
-
"to be translated %s more to be translated".t % user.name
Just make sure your translators don't mess up the %s placeholder.




Globalize can’t pass arguments ?
In globalite you can do this ;
:str.l_with_args({ :name => name })
And in your translation’s file :
str: Hello {name}