微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将po(gettext)转换为json?

我已经安装了po2json

npm install po2json

我收到以下错误

C:\windows\system32>po2json --errorlevel traceback fr.po fr.json
processing 1 files...

po2json: warning: Couldn't handle input file fr.po: Traceback (most recent call
last):

File "translate\misc\optrecurse.pyc",line 513,in recursiveprocess

File "translate\misc\optrecurse.pyc",line 417,in getoutputoptions
ValueError: don't kNow what to do with input format .po,no template file

我的fr.po文件在哪里

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-03-23 22:15+0530\n"
"PO-Revision-Date: 2015-03-23 22:21+0530\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-transfer-encoding: 8bit\n"
"Last-Translator: \n"
"Language-Team: \n"
"X-Generator: Poedit 1.7.4\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Language: fr\n"

\#: text.js:794

msgid "Search Files"

msgstr "Search Files french"

解决方法

这似乎使用了 Translate Toolkit,其中一些转换器如po2json在没有模板的情况下无法工作.也就是说,json2po可以解析JSON对象,但 po2json不知道如何创建JSON.虽然该联机帮助页具有误导性,将该模板标记为可选,但 documentation对此非常清楚.

要将未翻译的JSON文件指定为模板:

po2json -t english.json fr.po fr.json

如果您的原始文件test.js不是纯JSON文件,可解码为单个JSON对象,您可以尝试使用po2txt.

po2txt -t test.js fr.po test_fr.js

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐