diff --git a/integration/cli-hello-world-ivy-i18n/package.json b/integration/cli-hello-world-ivy-i18n/package.json index 5d02a4f3f8413..0c524ccf6b611 100644 --- a/integration/cli-hello-world-ivy-i18n/package.json +++ b/integration/cli-hello-world-ivy-i18n/package.json @@ -12,7 +12,7 @@ "start": "ng serve", "pretest": "ng version", "test": "ng test && yarn e2e --configuration=ci && yarn e2e --configuration=ci-production && yarn translated:test && yarn translated:legacy:test", - "translate": "localize-translate -r \"dist/\" -s \"**/*\" -l \"en-US\" -t \"src/locales/messages.*\" -o \"../tmp/translations/{{LOCALE}}\"", + "translate": "localize-translate -r \"dist/\" -s \"**/*\" -l \"en-US\" -t \"src/locales/messages.de.json\" \"src/locales/messages.fr.json\" -o \"../tmp/translations/{{LOCALE}}\"", "translated:test": "yarn build && yarn translate && yarn translated:fr:e2e && yarn translated:de:e2e && yarn translated:en:e2e", "translated:fr:serve": "serve ../tmp/translations/fr --listen 4200", "translated:fr:e2e": "npm-run-all -p -r translated:fr:serve \"ng e2e --configuration=translated-fr\"", diff --git a/packages/localize/src/tools/src/translate/main.ts b/packages/localize/src/tools/src/translate/main.ts index 3d3b9e92dc90d..e0af21ff7d4ac 100644 --- a/packages/localize/src/tools/src/translate/main.ts +++ b/packages/localize/src/tools/src/translate/main.ts @@ -47,8 +47,17 @@ if (require.main === module) { .option('t', { alias: 'translations', required: true, + array: true, describe: - 'A glob pattern indicating what translation files to load, either absolute or relative to the current working directory. E.g. `my_proj/src/locale/messages.*.xlf.', + 'A list of paths to the translation files to load, either absolute or relative to the current working directory.\n' + + 'E.g. "-t src/locale/messages.en.xlf src/locale/messages.fr.xlf src/locale/messages.de.xlf".', + }) + + .option('target-locales', { + array: true, + describe: + 'A list of target locales for the translation files, which will override any target locale parsed from the translation file.\n' + + 'E.g. "-t en fr de".', }) .option('o', { @@ -71,14 +80,12 @@ if (require.main === module) { const sourceRootPath = options['r']; const sourceFilePaths = glob.sync(options['s'], {absolute: true, cwd: sourceRootPath, nodir: true}); - const translationFilePaths = glob.sync(options['t'], {absolute: true, nodir: true}); + const translationFilePaths: string[] = options['t']; const outputPathFn = getOutputPathFn(options['o']); const diagnostics = new Diagnostics(); const missingTranslation: MissingTranslationStrategy = options['m']; const sourceLocale: string|undefined = options['l']; - // For CLI we do not have a way to specify the locale of the translation files - // It must be extracted from the file itself. - const translationFileLocales: string[] = []; + const translationFileLocales: string[] = options['target-locales'] || []; translateFiles({sourceRootPath, sourceFilePaths, translationFilePaths, translationFileLocales, outputPathFn, diagnostics, missingTranslation, sourceLocale});