i18n-polyfill
i18n-polyfill copied to clipboard
Using the ngx-extractor tool
Perhaps this is an incredibly silly question but I'm having issues using the tool as is. When I try to run it within my project directory after installing @ngx-translate/i18n-polyfill
it isn't able to find the command and when trying globally it fails because it isn't installing dependencies.
What should I be doing to have the example ngx-extractor -i src/**/*.ts -f xlf -o src/i18n/source.xlf
work within our project? I'm trying to add this to an existing script that's run to better automate translations.
(Apologies, it's been a long day on my end already!)
You can either add a ngx-extractor script in your package.json file:
...
"scripts": {
"ngx-extractor": "ngx-extractor"
}
}
...
and then run: npm run ngx-extrator [options]
Alternatively, you can run it directly with:
./node_modules/.bin/ngx-extractor
Oddly enough there seems to be a bug with running it this way. Unless I explicitly run it in the command line as node node_modules/.bin/ngx-extractor -i ./src/**/*.ts -o src/locale/messages.xlf
instead of npm run command
with the following..
{
"scripts": {
"command": "node node_modules/.bin/ngx-extractor -i ./src/**/*.ts -o src/locale/messages.xlf"
}
}
it refuses to work and doesn't generate the translations.
EDIT:
Looking into it and the regular expression doesn't get "expanded" to include all of the expected files in the scenario of it being run through npm
.
No need to add "node node_modules/.bin/ngx-extractor" in the scripts. Don't know if that would change anything for you. I do not personally use this method as we have a huge gulp script which runs a different node process separately.
That doesn't help but I essentially moved this two my own script and read in the file paths manually with that path expression and passed the list to the command.
try to scape the regex in your script, like:
"ng-extractor": "ngx-extractor -i \"./src/**/*.ts\" -o src/locale/source.xlf",
this will make the extractor run nicely with npm script
That helped, thank you.