feat(compiler-cli): add an `outFile` option to ng-xi18n
Fixes #11416 Closes #14508 Closes #14657
This commit is contained in:
parent
234f05996c
commit
39f56fafdd
|
@ -68,7 +68,7 @@ describe('template i18n extraction output', () => {
|
||||||
const genDir = 'out';
|
const genDir = 'out';
|
||||||
|
|
||||||
it('should extract i18n messages as xmb', () => {
|
it('should extract i18n messages as xmb', () => {
|
||||||
const xmbOutput = path.join(outDir, 'messages.xmb');
|
const xmbOutput = path.join(outDir, 'custom_file.xmb');
|
||||||
expect(fs.existsSync(xmbOutput)).toBeTruthy();
|
expect(fs.existsSync(xmbOutput)).toBeTruthy();
|
||||||
const xmb = fs.readFileSync(xmbOutput, {encoding: 'utf-8'});
|
const xmb = fs.readFileSync(xmbOutput, {encoding: 'utf-8'});
|
||||||
expect(xmb).toEqual(EXPECTED_XMB);
|
expect(xmb).toEqual(EXPECTED_XMB);
|
||||||
|
|
|
@ -132,6 +132,7 @@ function i18nTest() {
|
||||||
angularCompilerOptions: config.ngOptions,
|
angularCompilerOptions: config.ngOptions,
|
||||||
i18nFormat: 'xlf',
|
i18nFormat: 'xlf',
|
||||||
locale: null,
|
locale: null,
|
||||||
|
outFile: null,
|
||||||
readResource: (fileName: string) => {
|
readResource: (fileName: string) => {
|
||||||
readResources.push(fileName);
|
readResources.push(fileName);
|
||||||
return hostContext.readResource(fileName);
|
return hostContext.readResource(fileName);
|
||||||
|
|
|
@ -23,7 +23,7 @@ function extract(
|
||||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||||
program: ts.Program, host: ts.CompilerHost): Promise<void> {
|
program: ts.Program, host: ts.CompilerHost): Promise<void> {
|
||||||
return Extractor.create(ngOptions, program, host, cliOptions.locale)
|
return Extractor.create(ngOptions, program, host, cliOptions.locale)
|
||||||
.extract(cliOptions.i18nFormat);
|
.extract(cliOptions.i18nFormat, cliOptions.outFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry point
|
// Entry point
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class Extractor {
|
||||||
public host: ts.CompilerHost, private ngCompilerHost: CompilerHost,
|
public host: ts.CompilerHost, private ngCompilerHost: CompilerHost,
|
||||||
private program: ts.Program) {}
|
private program: ts.Program) {}
|
||||||
|
|
||||||
extract(formatName: string): Promise<void> {
|
extract(formatName: string, outFile: string|null): Promise<void> {
|
||||||
// Checks the format and returns the extension
|
// Checks the format and returns the extension
|
||||||
const ext = this.getExtension(formatName);
|
const ext = this.getExtension(formatName);
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ export class Extractor {
|
||||||
|
|
||||||
return promiseBundle.then(bundle => {
|
return promiseBundle.then(bundle => {
|
||||||
const content = this.serialize(bundle, ext);
|
const content = this.serialize(bundle, ext);
|
||||||
const dstPath = path.join(this.options.genDir, `messages.${ext}`);
|
const dstFile = outFile || `messages.${ext}`;
|
||||||
|
const dstPath = path.join(this.options.genDir, dstFile);
|
||||||
this.host.writeFile(dstPath, content, false);
|
this.host.writeFile(dstPath, content, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ export interface NgTools_InternalApi_NG2_ExtractI18n_Options {
|
||||||
readResource: (fileName: string) => Promise<string>;
|
readResource: (fileName: string) => Promise<string>;
|
||||||
// Every new property under this line should be optional.
|
// Every new property under this line should be optional.
|
||||||
locale?: string;
|
locale?: string;
|
||||||
|
outFile?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,6 +148,6 @@ export class NgTools_InternalApi_NG_2 {
|
||||||
const extractor = Extractor.create(
|
const extractor = Extractor.create(
|
||||||
options.angularCompilerOptions, options.program, options.host, locale, hostContext);
|
options.angularCompilerOptions, options.program, options.host, locale, hostContext);
|
||||||
|
|
||||||
return extractor.extract(options.i18nFormat);
|
return extractor.extract(options.i18nFormat, options.outFile || null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ cp -v package.json $TMP
|
||||||
./node_modules/.bin/ngc -p tsconfig-build.json --i18nFile=src/messages.fi.xlf --locale=fi --i18nFormat=xlf
|
./node_modules/.bin/ngc -p tsconfig-build.json --i18nFile=src/messages.fi.xlf --locale=fi --i18nFormat=xlf
|
||||||
|
|
||||||
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xlf --locale=fr
|
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xlf --locale=fr
|
||||||
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xmb
|
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xmb --outFile=custom_file.xmb
|
||||||
|
|
||||||
node test/test_summaries.js
|
node test/test_summaries.js
|
||||||
node test/test_ngtools_api.js
|
node test/test_ngtools_api.js
|
||||||
|
|
|
@ -11,13 +11,19 @@ export class CliOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class I18nExtractionCliOptions extends CliOptions {
|
export class I18nExtractionCliOptions extends CliOptions {
|
||||||
public i18nFormat: string;
|
i18nFormat: string|null;
|
||||||
public locale: string;
|
locale: string|null;
|
||||||
|
outFile: string|null;
|
||||||
|
|
||||||
constructor({i18nFormat = null, locale = null}: {i18nFormat?: string, locale: string|null}) {
|
constructor({i18nFormat = null, locale = null, outFile = null}: {
|
||||||
|
i18nFormat?: string,
|
||||||
|
locale?: string,
|
||||||
|
outFile?: string,
|
||||||
|
}) {
|
||||||
super({});
|
super({});
|
||||||
this.i18nFormat = i18nFormat;
|
this.i18nFormat = i18nFormat;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
|
this.outFile = outFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue