php string variables in gettext

旧巷老猫 提交于 2019-12-19 10:14:35

问题


How does gettext translate string variables? It doesn't seem to want to do it.. lets say I have $sentence = "Hello World"; and then I want to echo ($sentence); ... how can I do that so that I can translate what's inside $sentence in Poedit?I can use -> echo sprintf(("%s test"), $sentence) and this will print "Hello World test" in the browser but it will appear as "%s test" in Poedit and I won't get the translated version of Hello World inside of Poedit. So how can I use string variables inside Poedit? Thanks!


回答1:


You just must not have string variables. You should do e.g.

$sentance = _('Hello world');

The other way is to use some king of parser, which will be able to find your hello world strings and finally output somewhere

$fakie = _('Hello World');

This output should be stored in some file, which will then be pickedup by poedit and translated. For showing the translation you can than use

$myTranslation = _($sentance);

We used this conversion process for javascript files and smarty templates.




回答2:


There is detailed information available in http://us2.php.net/manual/en/book.gettext.php.



来源:https://stackoverflow.com/questions/1349159/php-string-variables-in-gettext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!