refactor(compiler): i18n - render legacy i18n message ids (#34135)
Now that `@angular/localize` can interpret multiple legacy message ids in the metablock of a `$localize` tagged template string, this commit adds those ids to each i18n message extracted from component templates, but only if the `enableI18nLegacyMessageIdFormat` is not `false`. PR Close #34135
This commit is contained in:

committed by
Miško Hevery

parent
8e96b450e2
commit
e524322c43
@ -52,7 +52,7 @@ export class ComponentDecoratorHandler implements
|
||||
private scopeReader: ComponentScopeReader, private scopeRegistry: LocalModuleScopeRegistry,
|
||||
private isCore: boolean, private resourceLoader: ResourceLoader, private rootDirs: string[],
|
||||
private defaultPreserveWhitespaces: boolean, private i18nUseExternalIds: boolean,
|
||||
private i18nLegacyMessageIdFormat: string, private moduleResolver: ModuleResolver,
|
||||
private enableI18nLegacyMessageIdFormat: boolean, private moduleResolver: ModuleResolver,
|
||||
private cycleAnalyzer: CycleAnalyzer, private refEmitter: ReferenceEmitter,
|
||||
private defaultImportRecorder: DefaultImportRecorder,
|
||||
private annotateForClosureCompiler: boolean,
|
||||
@ -710,7 +710,7 @@ export class ComponentDecoratorHandler implements
|
||||
preserveWhitespaces,
|
||||
interpolationConfig: interpolation,
|
||||
range: templateRange, escapedString,
|
||||
i18nLegacyMessageIdFormat: this.i18nLegacyMessageIdFormat, ...options,
|
||||
enableI18nLegacyMessageIdFormat: this.enableI18nLegacyMessageIdFormat, ...options,
|
||||
}),
|
||||
template: templateStr, templateUrl,
|
||||
isInline: component.has('template'),
|
||||
|
@ -63,7 +63,7 @@ runInEachFileSystem(() => {
|
||||
reflectionHost, evaluator, metaRegistry, metaReader, scopeRegistry, scopeRegistry,
|
||||
/* isCore */ false, new NoopResourceLoader(), /* rootDirs */[''],
|
||||
/* defaultPreserveWhitespaces */ false, /* i18nUseExternalIds */ true,
|
||||
/* i18nLegacyMessageIdFormat */ '', moduleResolver, cycleAnalyzer, refEmitter,
|
||||
/* enableI18nLegacyMessageIdFormat */ false, moduleResolver, cycleAnalyzer, refEmitter,
|
||||
NOOP_DEFAULT_IMPORT_RECORDER, /* annotateForClosureCompiler */ false);
|
||||
const TestCmp = getDeclaration(program, _('/entry.ts'), 'TestCmp', isNamedClassDeclaration);
|
||||
const detected = handler.detect(TestCmp, reflectionHost.getDecoratorsOfDeclaration(TestCmp));
|
||||
|
@ -623,9 +623,9 @@ export class NgtscProgram implements api.Program {
|
||||
this.reflector, evaluator, metaRegistry, this.metaReader !, scopeReader, scopeRegistry,
|
||||
this.isCore, this.resourceManager, this.rootDirs,
|
||||
this.options.preserveWhitespaces || false, this.options.i18nUseExternalIds !== false,
|
||||
this.getI18nLegacyMessageFormat(), this.moduleResolver, this.cycleAnalyzer,
|
||||
this.refEmitter, this.defaultImportTracker, this.closureCompilerEnabled,
|
||||
this.incrementalDriver),
|
||||
this.options.enableI18nLegacyMessageIdFormat !== false, this.moduleResolver,
|
||||
this.cycleAnalyzer, this.refEmitter, this.defaultImportTracker,
|
||||
this.closureCompilerEnabled, this.incrementalDriver),
|
||||
new DirectiveDecoratorHandler(
|
||||
this.reflector, evaluator, metaRegistry, this.defaultImportTracker, this.isCore,
|
||||
this.closureCompilerEnabled),
|
||||
@ -648,11 +648,6 @@ export class NgtscProgram implements api.Program {
|
||||
this.options.compileNonExportedClasses !== false);
|
||||
}
|
||||
|
||||
private getI18nLegacyMessageFormat(): string {
|
||||
return this.options.enableI18nLegacyMessageIdFormat !== false && this.options.i18nInFormat ||
|
||||
'';
|
||||
}
|
||||
|
||||
private get reflector(): TypeScriptReflectionHost {
|
||||
if (this._reflector === undefined) {
|
||||
this._reflector = new TypeScriptReflectionHost(this.tsProgram.getTypeChecker());
|
||||
|
@ -263,11 +263,10 @@ export interface CompilerOptions extends ts.CompilerOptions {
|
||||
i18nUseExternalIds?: boolean;
|
||||
|
||||
/**
|
||||
* Render `$localize` message ids with the legacy format (xlf, xlf2 or xmb) specified in
|
||||
* `i18nInFormat`.
|
||||
* Render `$localize` messages with legacy format ids.
|
||||
*
|
||||
* This is only active if we are building with `enableIvy: true` and a valid
|
||||
* `i18nInFormat` has been provided. The default value for now is `true`.
|
||||
* This is only active if we are building with `enableIvy: true`.
|
||||
* The default value for now is `true`.
|
||||
*
|
||||
* Use this option when use are using the `$localize` based localization messages but
|
||||
* have not migrated the translation files to use the new `$localize` message id format.
|
||||
|
Reference in New Issue
Block a user