i18n-polyfill icon indicating copy to clipboard operation
i18n-polyfill copied to clipboard

Using the ngx-extractor tool

Open mjschranz opened this issue 6 years ago • 6 comments

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

mjschranz avatar Apr 10 '18 15:04 mjschranz

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

wartab avatar Apr 11 '18 12:04 wartab

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.

mjschranz avatar Apr 11 '18 12:04 mjschranz

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.

wartab avatar Apr 11 '18 13:04 wartab

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.

mjschranz avatar Apr 11 '18 13:04 mjschranz

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

eloyleonardo avatar May 31 '18 13:05 eloyleonardo

That helped, thank you.

Thorusan avatar Apr 08 '19 08:04 Thorusan