2013-07-18 126 views
4

我正在尝试使用po2php将我的.po文件转换为Zend php翻译数组。如何使用Translate Toolkit将.po转换为PHP数组(Zend Framework)?

我只是试着这个:$ po2php translations.po translations.php,但这会导致一个我不明白的错误:po2php: warning: Couldn't handle input file translations.po: don't know what to do with input format .po, no template file

我不知道什么是模板文件是为什么我应该提供它?

更新:我也试过$ po2php translations.po translations.php -t messages.pot,但这并没有帮助我,它显示几乎相同的错误:po2php: warning: Couldn't handle input file translations.po: don't know what to do with input format .po, template format .pot

+0

为什么不使用Zend_Translate_Adapter_Gettext(http://framework.zend.com/manual/1.12/en/zend.translate.adapter.html)来使用.po /。 mo文件直接? –

+0

这只是我正在研究的项目的一项要求。历史原因... – ragulka

+0

对不起,不禁... :( –

回答

0

你也可以尝试梨包File_Gettext。在这里阅读更多:https://github.com/pear/File_Gettext

的代码应该是这样的(未测试):

include_once 'File/Gettext/PO.php'; 

$poFile = new File_Gettext_PO(); 
$poFile->load('PATH_TO/translations.po'); 

print_r($poFile->strings); 

$poFile->strings应包含PO文件关联数组的内容。接下来你需要一个函数来将这个数组输出到一个文件中。请看这里的第二个答案:Print array to a file

相关问题