Closed gatoenano closed 7 years ago
What version are you using? Are you getting an error message?
Thanks for your response
For the first example it creates a file called like './src/assets/i18n/{en,es,fr}.json '
For the second one, now it's working... I don't understand... I didn't anything!
Anyway, no errors appears at the terminal in both examples, just bad files, at least at the first example.
The version is 2.3.1
Many thanks!
Good to know!
I've received reports earlier about Windows not supporting file expansions ({en,es,fr}
). Are you on Windows, by any chance?
Sorry, I forgot to mention it. Yes I'm working with Win 7 64b
Got the same error. Is also a windows 10 64bit machine. Seems it doesn't support file expansion ({en, es, fr}
) nor glob pattern (*.json
). Only single filenames (e.g. base.json
) or a folder name (e.g. ./i18n/
) works. But by defining a folder it creates a single file named strings.json
.
Hope you'll find a solution to support this feature also on windows.
Sorry, I will not be adding support for this on Windows. I'll add a note to the README about the lack of Windows support.
I suggest you specify multiple output args to extract to multiple files. (... --output a.json --output b.json)
Using powershell or installing Cygwin might work too. Please try it and let me know how it goes :-)
My default work shell is the powershell. So this was already tested (without success). Just tried cygwin and calling directly ./node_modules/.bin/ngx-translate-extract ...
works (also with $'\t'
). But through npm it still fails. I guess this is because it is the windows version of npm which already breaks the command line parameters.
Just a thought, but what if you use --format-indentation=' ' when using npm ?
A good thought. 👍 It is not exactly correct, but pushed me into the right direction. What works is
"scripts": {
"extract": "ngx-translate-extract -i ./src -o ./src/i18n/en.json --clean --sort --format namespaced-json --format-indentation=\" \""
}
In the above example I inserted two spaces and that's exactly what came out in the json file. For getting tabs into the json the call should be:
"scripts": {
"extract": "ngx-translate-extract -i ./src -o ./src/i18n/en.json --clean --sort --format namespaced-json --format-indentation=\"\t\""
}
And if you want it really crazy, simply mix tabs and spaces:
"scripts": {
"extract": "ngx-translate-extract -i ./src -o ./src/i18n/en.json --clean --sort --format namespaced-json --format-indentation=\" \t \""
}
I use ubuntu and encounter this problem.
I solve the problem by changing shell in npm or yarn script using the following command
$ npm config set script-shell /bin/bash
// or yarn
$ yarn config set script-shell /bin/bash
and npm run extract
now expand glob pattern and save output files correctly.
Hope this help
I am windows user and I got the same error. I was getting really crazy
"extract-translations": "ngx-translate-extract --input ./src --output ./src/assets/i18n/de.json ./src/assets/i18n/en.json ./src/assets/i18n/es.json --clean --sort --format namespaced-json --marker _"
it is too long script but there is no other if you are windows user :(
On windows the solution is similar with @ball6847 's for ubuntu:
$ npm config set script-shell \"C:\\Program Files\\git\\bin\\bash.exe\"
$ ngx-translate-extract ...
$ npm config delete script-shell
Notice that for x86 installation of git you'll need to adjust the path:
$ npm config set script-shell \"C:\\Program Files (x86)\\git\\bin\\bash.exe\"
@sergiubologa your suggestion did not work for me and I have Windows. hmmm.
I recently came across the same issue and I've created a cross platform workaround that won't require any additional tooling or node_modules to be installed.
Example of my javascript file (cannot format cuz it uses backtics):
var exec = require('child_process').exec; const fs = require('fs'); const { languages } = JSON.parse(fs.readFileSync('./src/languages.json', 'utf8'));
exec(
ngx-translate-extract --input ./src --clean --sort --format namespaced-json ${languages .map(language =>
--output ./src/assets/i18n/${language}.json) .join(' ')}
,
(err, stdout, stderr) => {
if (err) {
throw new Error(err);
}
console.log(stdout);
console.error(stderr);
},
);
Example of my package.json script:
"scripts": { ... "extract-translations": "node extract-translations.js" },
Thank you ,
I appreciate your help.
Best Regards,
Karen Zavala
Karen Zavala
Dominican University Student
Hinda Incentives Intern
President of Technology Club
University Ministry Intern
From: ClaeysRune notifications@github.com Sent: Friday, July 3, 2020 2:39 AM To: biesbjerg/ngx-translate-extract ngx-translate-extract@noreply.github.com Cc: Zavala, Karen zavakare@my.dom.edu; Comment comment@noreply.github.com Subject: Re: [biesbjerg/ngx-translate-extract] Problems extracting and saving to multiple files (#53)
I recently came across the same issue and I've created a cross platform workaround that won't require any additional tooling or node_modules to be installed.
Example of my javascript file: `var exec = require('child_process').exec; const fs = require('fs'); const { languages } = JSON.parse(fs.readFileSync('./src/languages.json', 'utf8'));
exec( ngx-translate-extract --input ./src --clean --sort --format namespaced-json ${languages .map(language => --output ./src/assets/i18n/${language}.json) .join(' ')}, (err, stdout, stderr) => { if (err) { throw new Error(err); } console.log(stdout); console.error(stderr); }, );`
Example of my package.json script: "scripts": { ... "extract-translations": "node extract-translations.js" },
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/biesbjerg/ngx-translate-extract/issues/53#issuecomment-653401688, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD7QOHHZICQDGKGAZXVKGGTRZWDKPANCNFSM4DOZ4HGA.
readFileSync
can u send me a code
Hi biesbjerg!
I'm trying to extract and save to multiple files with the following code:
And also tried:
But doesn't work.
With a single file like ' ./src/assets/i18n/en.json' works, but not for multiple Any idea what it might be? I'm using npm 3.10
Many thanks in advance! Greetings