views:

49

answers:

1

Hi,

I am using .po and .mo files for translating my website. My question is, is it possible to pass parameters into a translated sentence in a .po translation file?

For example: en -> Hi, my name is Sarah, and I am an alcoholic I want to translate that sentence using two params, name (Sarah) and profession (an alcoholic).

Thank you in advance.

+1  A: 

It depends on the language, but basically, yes, you always can.

printf(_("Hi, my name is %s and I am %s"), name, prof);

in c.

echo sprintf(_("Hi, my name is %s and I am %s"), $name, $prof);

in php.

alert( _('Hi, my name is %s and I am %s')
    .replace('%s',name).replace('%s',prof) );

in javascript or better something like:

alert( _('Hi, my name is %1 and I am %2')
    .replace('%1',name).replace('%2',prof) );

or whatever you can come up with for a placeholder. Javascript implementation of course relies on having the translation mechanism provided either at preprocessing time or as a runtime underscore function.

and so forth.

Michael Krelin - hacker