7

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"
Thomas
  • 43,637
  • 12
  • 109
  • 140
rahulpatil
  • 71
  • 1
  • 3

1 Answers1

5

There are two different command line tools which are both called po2json. The first one is written in Javascript and can be installed from NPM. The second one is written in Python and can be installed from PIP. The Javascript po2json produces JSON equivalents from dictionaries of untranslated and translated entries in gettext format (PO files). The Python po2json produces translated JSON documents from untranslated JSON documents and PO files.

Your call to po2json seems to execute the Python program. While you seem to have the Javascript program installed as well, it is apparently not executed. Probably you have both versions on the path, but the Python one takes precedence over the Javascript one. Check your PATH environment variable. Maybe the directory containing po2json.py is listed before the directory containing po2json.js. Or try po2json --help, I think the Javascript file does not allow this option.

The Python po2json is part of the Translate Toolkit, where some converters such as po2json do not work without a template. With json2po you can parse untranslated JSON objects and create POT files which contain the untranslated text pieces. Then, after carrying out the translation, you have a PO file with untranslated and translated entries. This is only useful together with the original untranslated JSON document, because otherwise po2json does not know how to recreate 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 en-fr.po french.json

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

po2txt -t english.js en-fr.po french.js
hlg
  • 1,321
  • 13
  • 29
  • 2
    This is stupid, at least with php2po and po2php. I have tried the po2php and it resulted with same error as OP, then tried your solution and i must say, this po2php is complete failure. It requires template file, but the output file turns out to be exactly like a template file. Seriously, if i have .po and want to get .php, how on earth does one get a .php file for the template if you only have .po file? – user1651105 Dec 07 '17 at 10:03
  • @hlg This is not a good answer, while you could type example template format as code. – Keso Nov 02 '22 at 09:33
  • @Keso I have updated the answer for clarification. Hope that helps. – hlg Nov 05 '22 at 10:16