问题
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