开发者

i18n on a variable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜