Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn xliffmerge argument parser broken #144

Open
pinetree62 opened this issue Jun 20, 2019 · 5 comments
Open

yarn xliffmerge argument parser broken #144

pinetree62 opened this issue Jun 20, 2019 · 5 comments

Comments

@pinetree62
Copy link

pinetree62 commented Jun 20, 2019

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.

@synthet
Copy link

synthet commented Oct 21, 2019

I have the same issue running xliffmerge on windows / npm

@martinroob
Copy link
Owner

Sorry for this very late response.
Will have a look at it and fix it in the next version.

@synthet
Copy link

synthet commented Oct 28, 2019

I have used patch-package tool with change suggested by @pinetree62 as a workaround.

@MarcusRiemer
Copy link

MarcusRiemer commented Jan 21, 2021

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.

@hansmaad
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants