How to convert .po to PHP array (Zend Framework) with Translate Toolkit?

ε祈祈猫儿з 提交于 2019-12-07 11:19:33

问题


I am trying to use po2php to convert my .po file to Zend php translations array.

I am simply trying this: $ po2php translations.po translations.php, but this results in an error that I do not understand: po2php: warning: Couldn't handle input file translations.po: don't know what to do with input format .po, no template file.

I do not know what a template file is an why should I provide it?

UPDATE: I also tried $ po2php translations.po translations.php -t messages.pot, but this does not help me, it shows pretty much the same error: po2php: warning: Couldn't handle input file translations.po: don't know what to do with input format .po, template format .pot.


回答1:


You could also try out the pear package File_Gettext. Read more here: https://github.com/pear/File_Gettext

The code would look like this (Not tested):

include_once 'File/Gettext/PO.php';

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

print_r($poFile->strings);

$poFile->strings should contain the content of the po file as associative array. Next you need a function to output this array in a file. Take a look at the second answer here: Print array to a file



来源:https://stackoverflow.com/questions/17727457/how-to-convert-po-to-php-array-zend-framework-with-translate-toolkit

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