fix(ivy): i18n - update localize-translate
to accept target-locales (#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
This commit is contained in:
parent
62b2840822
commit
41979d6a27
@ -12,7 +12,7 @@
|
|||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"pretest": "ng version",
|
"pretest": "ng version",
|
||||||
"test": "ng test && yarn e2e --configuration=ci && yarn e2e --configuration=ci-production && yarn translated:test && yarn translated:legacy:test",
|
"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: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:serve": "serve ../tmp/translations/fr --listen 4200",
|
||||||
"translated:fr:e2e": "npm-run-all -p -r translated:fr:serve \"ng e2e --configuration=translated-fr\"",
|
"translated:fr:e2e": "npm-run-all -p -r translated:fr:serve \"ng e2e --configuration=translated-fr\"",
|
||||||
|
@ -47,8 +47,17 @@ if (require.main === module) {
|
|||||||
.option('t', {
|
.option('t', {
|
||||||
alias: 'translations',
|
alias: 'translations',
|
||||||
required: true,
|
required: true,
|
||||||
|
array: true,
|
||||||
describe:
|
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', {
|
.option('o', {
|
||||||
@ -71,14 +80,12 @@ if (require.main === module) {
|
|||||||
const sourceRootPath = options['r'];
|
const sourceRootPath = options['r'];
|
||||||
const sourceFilePaths =
|
const sourceFilePaths =
|
||||||
glob.sync(options['s'], {absolute: true, cwd: sourceRootPath, nodir: true});
|
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 outputPathFn = getOutputPathFn(options['o']);
|
||||||
const diagnostics = new Diagnostics();
|
const diagnostics = new Diagnostics();
|
||||||
const missingTranslation: MissingTranslationStrategy = options['m'];
|
const missingTranslation: MissingTranslationStrategy = options['m'];
|
||||||
const sourceLocale: string|undefined = options['l'];
|
const sourceLocale: string|undefined = options['l'];
|
||||||
// For CLI we do not have a way to specify the locale of the translation files
|
const translationFileLocales: string[] = options['target-locales'] || [];
|
||||||
// It must be extracted from the file itself.
|
|
||||||
const translationFileLocales: string[] = [];
|
|
||||||
|
|
||||||
translateFiles({sourceRootPath, sourceFilePaths, translationFilePaths, translationFileLocales,
|
translateFiles({sourceRootPath, sourceFilePaths, translationFilePaths, translationFileLocales,
|
||||||
outputPathFn, diagnostics, missingTranslation, sourceLocale});
|
outputPathFn, diagnostics, missingTranslation, sourceLocale});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user