biesbjerg / ngx-translate-extract

Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file
MIT License
524 stars 198 forks source link

Problems extracting and saving to multiple files #53

Closed gatoenano closed 7 years ago

gatoenano commented 7 years ago

Hi biesbjerg!

I'm trying to extract and save to multiple files with the following code:

"extract": "ngx-translate-extract --input ./src/app/ --output ./src/assets/i18n/{en,es,fr}.json --clean --sort --format namespaced-json"

And also tried:

"extract": "ngx-translate-extract --input ./src/app/ --output ./src/assets/i18n/en.json ./src/assets/i18n/es.json ./src/assets/i18n/fr.json --clean --sort --format namespaced-json"

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

biesbjerg commented 7 years ago

What version are you using? Are you getting an error message?

gatoenano commented 7 years ago

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!

biesbjerg commented 7 years ago

Good to know!

I've received reports earlier about Windows not supporting file expansions ({en,es,fr}). Are you on Windows, by any chance?

gatoenano commented 7 years ago

Sorry, I forgot to mention it. Yes I'm working with Win 7 64b

olivermue commented 7 years ago

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.

biesbjerg commented 7 years ago

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)

biesbjerg commented 7 years ago

Using powershell or installing Cygwin might work too. Please try it and let me know how it goes :-)

olivermue commented 7 years ago

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.

biesbjerg commented 7 years ago

Just a thought, but what if you use --format-indentation=' ' when using npm ?

olivermue commented 7 years ago

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  \""
}
ball6847 commented 6 years ago

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

lizzymendivil commented 6 years ago

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 :(

sergiubologa commented 5 years ago

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\"
zavakare commented 4 years ago

@sergiubologa your suggestion did not work for me and I have Windows. hmmm.

RuneClaeys commented 4 years ago

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.

  1. First I created a json file containing a list of all the languages my application has (this is optional but I need the list in multiple parts of my application).
  2. Then I created a javascript file that loops trough all the languages defined in the json file (you could just hardcode them all here) and append them to the ngx-translate-extract command. And running it using child_processes.exec (included in node)
  3. Finally I changed the command in my package.json to node extract-translations.js (aka your javascript file)

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" },

zavakare commented 4 years ago

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.

  1. First I created a json file containing a list of all the languages my application has (this is optional but I need the list in multiple parts of my application).
  2. Then I created a javascript file that loops trough all the languages defined in the json file (you could just hardcode them all here) and append them to the ngx-translate-extract command. And running it using child_processes.exec (included in node)
  3. Finally I changed the command in my package.json to node extract-translations.js (aka your javascript file)

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.

HadyMohamedMorsy commented 1 year ago

readFileSync

can u send me a code