How to convert .po to PHP array (Zend Framework) using translation tools?

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

I'm just trying to do this: $ po2php translations.po translations.php , but this leads to an error that I don't 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, why should I provide it?

UPDATE: I also tried $ po2php translations.po translations.php -t messages.pot , but it doesn’t help me, it shows almost 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 .

+4
source share
1 answer

You can also try the File_Gettext pear package . More details here: https://github.com/pear/File_Gettext

The code will look like this (not verified):

 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 contents of the po file as an associative array. Then you need a function to output this array to a file. Take a look at the second answer here: Print an array to a file

0
source

Source: https://habr.com/ru/post/1492117/


All Articles