ngx-i18nsupport
ngx-i18nsupport copied to clipboard
yarn xliffmerge argument parser broken
using your latest version from today:
My Environment:
- ubuntu 19.04
- node 12.4
- angular 8.0.0.1
- yarn 1.16.0 and 1.17.0
- ngx-i18nsupport: 1.1.6
yarn xliffmerge fails to run, it seems to get an extra parameter which it interprets as a language this paramer is the path of xliffmerge (i redacted the paths a little bit)
yarn xliffmerge -p xliffmerge.json -v en
xliffmerge -p xliffmerge.json -v en
* xliffmerge version 1.1.6
* xliffmerge Used Parameters:
* usedProfilePath: "xliffmerge.json"
* defaultLanguage: "en"
* srcDir: "src/locale"
* genDir: "src/locale"
* i18nBaseFile: "messages"
* i18nFile: "src/locale/messages.xlf"
* languages: /home/XYZ/src/node_modules/.bin/xliffmerge,en,de,fr,it
* outputFile[/home/XYZ/src//node_modules/.bin/xliffmerge]: src/locale/messages./homeXYZ/src/node_modules/.bin/xliffmerge.xlf
* outputFile[en]: src/locale/messages.en.xlf
* outputFile[de]: src/locale/messages.de.xlf
* outputFile[fr]: src/locale/messages.fr.xlf
* outputFile[it]: src/locale/messages.it.xlf
* removeUnusedIds: true
* supportNgxTranslate: false
* useSourceAsTarget: true
* targetPraefix: ""
* targetSuffix: ""
* allowIdChange: true
* beautifyOutput: false
* preserveOrder: true
* autotranslate: false
ERROR: language "/home/XYZ/src/node_modules/.bin/xliffmerge" is not valid
error Command failed with exit code 255.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
in your file xliff-merge.js where the command line arguments are parsed
static parseArgs(argv) {
const options = {
languages: []
};
for (let i = 1; i < argv.length; i++) {
const arg = argv[i];
its starting from 1, From what I read here: (found in the internet ;))
// print process.argv
process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
This will generate:
$ node process-2.js one two=three four
0: node
1: /Users/mjr/work/node/process-2.js
2: one
3: two=th
the "real" arguments also should start from 2 not 1.
So if i change line 53 to
for (let i = 2; i < argv.length; i++) {
it works for me.
As an alternative: addind to the parseArgs something like
else if (arg.length > 0 && arg.charAt(0) === '/') {
console.log('ignore this');
}
works too, but i guess thats not generic enough.
Not sure whether this is specific to using yarn or my setup.
I have the same issue running xliffmerge on windows / npm
Sorry for this very late response. Will have a look at it and fix it in the next version.
I have used patch-package tool with change suggested by @pinetree62 as a workaround.
This issue is still present, I can only run xliffmerge
from the commandline when discarding the first argument. Otherwise the path to the xliffmerge
"binary" entry file is mistaken as a language.
Is there any chance of a hotfix specifically for xliffmerge
? I do understand that keeping up with Angulars Builder API is an invidious task, but this neat little tool works quite fine on its own.
As a workaround for Angular 10+, I created a small script to directly call the xliffmerge function
const xliffmerge = require('@ngx-i18nsupport/ngx-i18nsupport/src/xliffmerge/xliff-merge');
xliffmerge.XliffMerge.main([process.argv[0], ...process.argv.slice(2)]);
I call it from package.json
"xi18n:merge": "node xliffmerge.js --profile xliffmerge.json en de"