开发者

i18n on a variable

开发者 https://www.devze.com 2022-12-08 04:23 出处:网络
I would like t开发者_如何学Co know if I can use a gt function on a variable with php? eg. : echo _($var);Feel free to. But you need to make sure the possible contents of the variable makes it into .p

I would like t开发者_如何学Co know if I can use a gt function on a variable with php?

eg. : echo _($var);


Feel free to. But you need to make sure the possible contents of the variable makes it into .po/.mo files. (one of the ways to do assure it is to create a dummy file never processed except for by xgettext, containing _("translate me"); expressions).


I don't think gettext will recognize a variable since it scans the source code. If you want to include variables in a string, it's better to use

sprintf()

For example

echo sprintf(_("There are %d results!"), $numResults);

In gettext, the translator will see

There are %d results!

so therefore it can easily be translated as long as he/she knows that %d is a variable. When the script gets executed, gettext will first replace the translation, and then sprintf will insert the variable $numResults. Good luck! I just got done internationalizing my site.

0

精彩评论

暂无评论...
验证码 换一张
取 消