2013-07-18 29 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

相關問題