ngx-translate / i18n-polyfill

A speculative polyfill to support i18n code translations in Angular
MIT License
139 stars 30 forks source link

Using the ngx-extractor tool #19

Open mjschranz opened 6 years ago

mjschranz commented 6 years ago

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!)

wartab commented 6 years ago

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

mjschranz commented 6 years ago

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.

wartab commented 6 years ago

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.

mjschranz commented 6 years ago

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.

eloyleonardo commented 6 years ago

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

Thorusan commented 5 years ago

That helped, thank you.