我正在使用PHP、Zend Framework和 Zend_Translate(gettext 适配器)。为了编辑翻译,我使用POEdit,它利用xgettext来获取要翻译的字符串。
POEdit (xgettext) 将搜索关键字以查找要翻译的字符串。因此,如果搜索关键字,当文本直接传递给翻译函数时translate
,POEdit 将没有问题找到字符串,如:'Text to translate'
echo translate('Text to translate');
但是,在其他情况下,字符串将被传递给 Zend 函数,这些函数将为我进行翻译,调用带有变量作为参数的 translate 函数:
function SomeZendFunction( $array ) {
return translate( $array['string'] );
}
...
echo SomeZendFunction( array('string'=>'Another text to translate') );
// translate('Another text to translate');
这将导致 POEdit (xgettext) 无法找到要翻译的字符串。在上面的示例中,我希望 POEdit 查找的字符串是'Another text to translate'
,但由于它没有直接传递给translate
函数,因此找不到。
那么,如何解决问题呢?
我当前的解决方案是创建一个虚拟文件,其中包含 POEdit 未找到的所有字符串的长列表:
<?php // Dummy file, only accessed by POEdit when scanning for strings to translate
translate('Text to translate');
translate('Another text to translate');
translate('A third text to translate');
....
但是这个解决方案的缺点是更新字符串时,我都需要更改虚拟文件并找到原始字符串。这将使其更难维护。
我想到的另一个解决方案是在调用后将翻译字符串添加到评论中SomeZendFunction
(参见上面的示例),但我无法让 xgettext 接受它,因为它忽略了评论。
那么,任何人都知道如何让 xgettext 接受评论中的字符串?或者任何人有任何其他可能更好的解决方案?
谢谢你的帮助!
编辑:
我不知道为什么我被否决了。但我试图澄清这个问题。