gettext中的php字符串变量(忘记一种情况) [英] php string variables in gettext (forgot one case scenario)
问题描述
我昨天发布了一个问题,但是我只是意识到答案似乎在某些情况下不起作用.帖子是 gettext中的php字符串变量,这是我问的关于:
I've posted a question yesterday but I just realized that the answer doesn't seem to be working for a certain situation. The post was php string variables in gettext and here is what I asked about:
你好
gettext如何翻译字符串 变量?它似乎不想 做到..可以说我有$ sentence = 你好,世界";然后我想回声 ($句); ...我该怎么做 我可以翻译里面的东西 我可以使用-> echo在Poedit中使用$ sentence吗? sprintf(((%s test"),$ sentence)和 这将在 浏览器,但显示为%s" 测试"中,而我不会 Hello World的翻译版本 在Poedit内部.那我该怎么用 Poedit中的字符串变量? 谢谢!
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!
此问题已解决.
如果我想从XML文件中获取数据并进行翻译,则会出现问题.
The problem occurs if I want to grab data from an XML file and translate it.
我希望能够执行以下操作:
I want to be able to do the following:
$foo = $xmlData -> titleText;
然后
echo _($foo);
或类似
$finalVar = _($foo);
如果我在浏览器中查看php文件,我可以在页面上看到$ foo的内容,但是Poedit不会在$ foo中拾取字符串,所以我可以翻译它.
If I look at the php file in the browser I can see the content of $foo on the page but Poedit doesn't pick up the string inside $foo so I can translate it.
(我相信在js文件中翻译信息时也会出现此问题)
(I believe this problem will also occur when translating info within js files)
感谢您的帮助,
西蒙(Simon)
推荐答案
很显然,您无法使Poedit理解PHP.
Obviously you can't make Poedit understand PHP.
编辑:您考虑过其他方法吗?
EDIT: Have you considered a different approach?
if (true) {
$foo = _('variable holds true');
}
else {
$foo = _('variable holds false');
}
echo $foo;
您可以让PHP生成与gettext兼容的XML,并与数据库有关,我相信最好的解决方案是将翻译存储在DB本身中,但是您也可以创建一个脚本来转储数据库中的所有键和值,以及在其上使用gettext.
You can have PHP generated the gettext compatible XML and regarding the database, I believe the best solution is to store the translation in the DB itself, however you can also create a script to dump all the keys and values from the database and use gettext on it.
这篇关于gettext中的php字符串变量(忘记一种情况)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!