i18n变量

I would like to know if I can use a gt function on a variable with php?

eg. : echo _($var);

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.

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