Can I transfer parameters to a translated sentence in a .po translation file?

I use the files .poand .moto translate my site. My question is, is it possible to pass parameters to the translated sentence in . Translation file

For example: ru → Hello, my name is Sarah and I am an alcoholic. I want to translate this sentence using two parameters, name (Sarah) and profession (alcoholic).

Thanks in advance.

+3
source share
2 answers

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

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) );

, . , Javascript , , .

..

+9

, ...

, , ( PHP):

$name = 'Agustinus';
printf(_("Hi %1$s.\n The owner of this page is: %1$s. Today is %s.", 
   $name, date('d-m-Y'));
0

Source: https://habr.com/ru/post/1718023/


All Articles