如何将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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...