如何使用Translate Toolkit将.po转换为PHP数组(Zend Framework)? [英] How to convert .po to PHP array (Zend Framework) with Translate Toolkit?

查看:145
本文介绍了如何使用Translate Toolkit将.po转换为PHP数组(Zend Framework)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 po2php 将我的.po文件转换为Zend php translations数组.

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

我只是在尝试:$ 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.

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?

更新:我也尝试过$ 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.

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.

推荐答案

您还可以尝试使用梨包 File_Gettext .在此处阅读更多信息: https://github.com/pear/File_Gettext

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应该包含po文件的内容作为关联数组.接下来,您需要一个函数将此数组输出到文件中.在这里查看第二个答案:将数组打印到文件中

$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

这篇关于如何使用Translate Toolkit将.po转换为PHP数组(Zend Framework)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆