Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert po (gettext) to json?

Tags:

json

gettext

I have installed po2json using

npm install po2json

I am getting below error:

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

where as my fr.po file is

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"
like image 807
rahulpatil Avatar asked Nov 01 '22 07:11

rahulpatil


1 Answers

This seems to use the Translate Toolkit, where some converters such as po2json do not work without a template. That is, json2po can parse JSON objects, but po2json does not know how to create JSON. While the manpage is misleading, marking the template as optional, the documentation is correct clear about this.

To specify the untranslated JSON file as template:

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

In case your original file test.js is not a pure JSON file, decodable as a single JSON object, you could try to use po2txt instead.

po2txt -t test.js fr.po test_fr.js
like image 115
hlg Avatar answered Nov 29 '22 20:11

hlg