Skip to content

Commit

Permalink
fix(ivy): i18n - update localize-translate to accept target-locales (
Browse files Browse the repository at this point in the history
…#33381)

The `localize-translate` command line tool can now accept an array of
target locales to support the case where translation files do not
contain them. Specify this array via the `--target-locales` option.

NOTE to early adopters: in order to support this, the original `-t`
option for the binary has changed from being a glob pattern to an array
of paths, which will have matching indices to any provided target-locales.

PR Close #33381
  • Loading branch information
petebacondarwin authored and AndrewKushnir committed Oct 28, 2019
1 parent 62b2840 commit 41979d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration/cli-hello-world-ivy-i18n/package.json
Expand Up @@ -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\"",
Expand Down
17 changes: 12 additions & 5 deletions packages/localize/src/tools/src/translate/main.ts
Expand Up @@ -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', {
Expand All @@ -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});
Expand Down

0 comments on commit 41979d6

Please sign in to comment.