ttag-cli icon indicating copy to clipboard operation
ttag-cli copied to clipboard

Unvalid JSON export

Open adrien-castagliola-cbp opened this issue 6 years ago • 6 comments

Hello, I'm trying to export a .po file to a .json file but it doesn't seem to be a valid one. Indeed, a path is added at the top of the json file.

The command i'm using : npx ttag po2json i18n/uk.po > i18n/uk.po.json

Here is my uk.po file :

msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Plural-Forms: nplurals = 3; plural = (n % 10 == 1 && n % 100 != 11 ? 0 : n "
"% 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);\n"
"Language: uk\n"
"mime-version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"

#: src\App.js:6
msgid "Learn React"
msgstr "Вивчити React"

here is my uk.po.json file :

C:\Users\castagliol\dev\ttag-app\node_modules\ttag-cli\bin\ttag
{"charset":"utf-8","headers":{"content-type":"text/plain; charset=utf-8","plural-forms":"nplurals = 3; plural = (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);","language":"uk","mime-version":"1.0","content-transfer-encoding":"8bit"},"translations":{"":{"":{"msgid":"","msgstr":["Content-Type: text/plain; charset=utf-8\nPlural-Forms: nplurals = 3; plural = (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);\nLanguage: uk\nmime-version: 1.0\nContent-Transfer-Encoding: 8bit\n"]},"Learn React":{"msgid":"Learn React","msgstr":["ðÆð©ð▓Ðçð©Ðéð© React"]}}}}

Tested on Windows, [email protected]

adrien-castagliola-cbp avatar Apr 29 '19 08:04 adrien-castagliola-cbp

Hi @adrien-castagliola-cbp! Thanks for the report! Seems like that this shortcut is valid for Unix based systems like Linux or MacOS. I agree that we should have separate specific instructions for the Windows. I'm not quite fluent at windows batch syntax, will try to investigate that issue. Any help will be appreciated also.

AlexMost avatar Apr 29 '19 09:04 AlexMost

Tried to reproduce that case on the Windows 7. And received a valid json. Which version of nodejs and Windows do you use?

AlexMost avatar Apr 29 '19 09:04 AlexMost

Hello,

Thanks for answering me,

Node: v8.11.3 Windows: v10.0.16299

Le lun. 29 avr. 2019 à 11:41, Alexander [email protected] a écrit :

Tried to reproduce that case on the Windows 7. And received a valid json. Which version of nodejs and Windows do you use?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ttag-org/ttag-cli/issues/71#issuecomment-487517978, or mute the thread https://github.com/notifications/unsubscribe-auth/ALXILXSPIPHHDAK52MCIKYLPS27GHANCNFSM4HJBJ6AA .

--


La diffusion de ce message s'effectuant sur un réseau non protégé, nous déclinons toute responsabilité en cas d'altération ou de falsification. As this message is sent through a non protected network, we decline any responsibility should it be altered or falsified


adrien-castagliola-cbp avatar Apr 29 '19 11:04 adrien-castagliola-cbp

Hi @AlexMost,

I am also facing the same issue. I got this in the po.json file.

yarn run v1.16.0 $ /home/daffodil/react/firelab_superadmin_web/node_modules/.bin/ttag po2json i18n/en.po {"charset":"utf-8","headers":{"content-type":"text/plain; charset=utf-8","plural-forms":"nplurals = 2; plural = (n != 1);","language":"en","mime-version":"1.0","content-transfer-encoding":"8bit"},"translations":{"":{"":{"msgid":"","msgstr":["Content-Type: text/plain; charset=utf-8\nPlural-Forms: nplurals = 2; plural = (n != 1);\nLanguage: en\nmime-version: 1.0\nContent-Transfer-Encoding: 8bit\n"]}}}}Done in 0.51s.

please resolve this asap.

tushargargdaffodil avatar Jul 16 '19 11:07 tushargargdaffodil

TL;DR

yarn run --silent ... och samma på npx

Long read

yarn adding some output (the other possibility is stdout/stderr mixup).

This is what I use:

for PO in int/*.po;
  yarn run --silent ttag po2json --pretty $PO > tmp.json
  mv tmp.json (string replace int/ src/int/ (string replace .po .json $PO))
end
  • yarn run --silent suppresses the script path and Done in Xs outputs
  • ... > tmp.json; mv tmp.json final.json so that incremental build works(*)
  • --pretty for smaller/saner diffs if JSON is checked in

(*) shell redirect truncates the file first, then ttag runs and eventually fills the file with output, if the file is a build dependency, tools like yarn start will attempt to use the file while it's still empty.

dimaqq avatar Sep 19 '19 08:09 dimaqq

IMO the correct way to "solve" this is to add -o output_file argument to the command, which would do the right thing (save output to temp file, if there's no error, replace the target).

For example yarn pseudo has such option.

dimaqq avatar Sep 19 '19 08:09 dimaqq