Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unvalid JSON export #71

Open
adrien-castagliola-cbp opened this issue Apr 29, 2019 · 6 comments
Open

Unvalid JSON export #71

adrien-castagliola-cbp opened this issue Apr 29, 2019 · 6 comments

Comments

@adrien-castagliola-cbp
Copy link

adrien-castagliola-cbp commented Apr 29, 2019

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]

@AlexMost
Copy link
Member

AlexMost commented Apr 29, 2019

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 AlexMost pinned this issue Apr 29, 2019
@AlexMost AlexMost unpinned this issue Apr 29, 2019
@AlexMost
Copy link
Member

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

@adrien-castagliola-cbp
Copy link
Author

adrien-castagliola-cbp commented Apr 29, 2019 via email

@tushargargdaffodil
Copy link

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.

@dimaqq
Copy link
Contributor

dimaqq commented Sep 19, 2019

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
Copy link
Contributor

dimaqq commented Sep 19, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants