feat(compiler-cli): add a locale
option to ng-xi18n
Fixes #12303 Closes #14537
This commit is contained in:
@ -22,7 +22,8 @@ import {Extractor} from './extractor';
|
||||
function extract(
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||
program: ts.Program, host: ts.CompilerHost): Promise<void> {
|
||||
return Extractor.create(ngOptions, program, host).extract(cliOptions.i18nFormat);
|
||||
return Extractor.create(ngOptions, program, host, cliOptions.locale)
|
||||
.extract(cliOptions.i18nFormat);
|
||||
}
|
||||
|
||||
// Entry point
|
||||
|
@ -73,7 +73,8 @@ export class Extractor {
|
||||
|
||||
static create(
|
||||
options: tsc.AngularCompilerOptions, program: ts.Program, tsCompilerHost: ts.CompilerHost,
|
||||
compilerHostContext?: CompilerHostContext, ngCompilerHost?: CompilerHost): Extractor {
|
||||
locale?: string|null, compilerHostContext?: CompilerHostContext,
|
||||
ngCompilerHost?: CompilerHost): Extractor {
|
||||
if (!ngCompilerHost) {
|
||||
const usePathMapping = !!options.rootDirs && options.rootDirs.length > 0;
|
||||
const context = compilerHostContext || new ModuleResolutionHostAdapter(tsCompilerHost);
|
||||
@ -81,7 +82,7 @@ export class Extractor {
|
||||
new CompilerHost(program, options, context);
|
||||
}
|
||||
|
||||
const {extractor: ngExtractor} = compiler.Extractor.create(ngCompilerHost);
|
||||
const {extractor: ngExtractor} = compiler.Extractor.create(ngCompilerHost, locale || null);
|
||||
|
||||
return new Extractor(options, ngExtractor, tsCompilerHost, ngCompilerHost, program);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ export interface NgTools_InternalApi_NG2_ExtractI18n_Options {
|
||||
i18nFormat: string;
|
||||
readResource: (fileName: string) => Promise<string>;
|
||||
// Every new property under this line should be optional.
|
||||
locale?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,8 +143,9 @@ export class NgTools_InternalApi_NG_2 {
|
||||
new CustomLoaderModuleResolutionHostAdapter(options.readResource, options.host);
|
||||
|
||||
// Create the i18n extractor.
|
||||
const locale = options.locale || null;
|
||||
const extractor = Extractor.create(
|
||||
options.angularCompilerOptions, options.program, options.host, hostContext);
|
||||
options.angularCompilerOptions, options.program, options.host, locale, hostContext);
|
||||
|
||||
return extractor.extract(options.i18nFormat);
|
||||
}
|
||||
|
Reference in New Issue
Block a user