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
7414ece2fa
commit
33d3340bac
@ -210,7 +210,8 @@ export function compile(
|
||||
scripts, {
|
||||
target: ts.ScriptTarget.ES2015,
|
||||
module: ts.ModuleKind.ES2015,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs, ...options,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
enableI18nLegacyMessageIdFormat: false, ...options,
|
||||
},
|
||||
mockCompilerHost);
|
||||
program.emit();
|
||||
|
@ -3457,6 +3457,38 @@ describe('i18n support in the template compiler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('$localize legacy message ids', () => {
|
||||
it('should add legacy message ids if `enableI18nLegacyMessageIdFormat` is true', () => {
|
||||
const input = `<div i18n>Some Message</div>`;
|
||||
|
||||
const output = String.raw `
|
||||
var $I18N_0$;
|
||||
if (ngI18nClosureMode) { … }
|
||||
else {
|
||||
$I18N_0$ = $localize \`:␟ec93160d6d6a8822214060dd7938bf821c22b226␟6795333002533525253:Some Message\`;
|
||||
}
|
||||
…
|
||||
`;
|
||||
|
||||
verify(input, output, {compilerOptions: {enableI18nLegacyMessageIdFormat: true}});
|
||||
});
|
||||
|
||||
it('should add legacy message ids if `enableI18nLegacyMessageIdFormat` is undefined', () => {
|
||||
const input = `<div i18n>Some Message</div>`;
|
||||
|
||||
const output = String.raw `
|
||||
var $I18N_0$;
|
||||
if (ngI18nClosureMode) { … }
|
||||
else {
|
||||
$I18N_0$ = $localize \`:␟ec93160d6d6a8822214060dd7938bf821c22b226␟6795333002533525253:Some Message\`;
|
||||
}
|
||||
…
|
||||
`;
|
||||
|
||||
verify(input, output, {compilerOptions: {enableI18nLegacyMessageIdFormat: undefined}});
|
||||
});
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
const verifyNestedSectionsError = (errorThrown: any, expectedErrorText: string) => {
|
||||
expect(errorThrown.ngParseErrors.length).toBe(1);
|
||||
|
Reference in New Issue
Block a user