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:
Pete Bacon Darwin
2019-12-03 08:36:38 +00:00
committed by Miško Hevery
parent 8e96b450e2
commit e524322c43
12 changed files with 100 additions and 124 deletions

View File

@ -1945,17 +1945,14 @@ export interface ParseTemplateOptions {
leadingTriviaChars?: string[];
/**
* Render `$localize` message ids with the specified legacy format (xlf, xlf2 or xmb).
* Render `$localize` message ids with additional legacy message ids.
*
* 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.
* This option defaults to `true` but in the future the defaul will be flipped.
*
* @deprecated
* `i18nLegacyMessageIdFormat` should only be used while migrating from legacy message id
* formatted translation files and will be removed at the same time as ViewEngine support is
* removed.
* For now set this option to false if you have migrated the translation files to use the new
* `$localize` message id format and you are not using compile time translation merging.
*/
i18nLegacyMessageIdFormat?: string;
enableI18nLegacyMessageIdFormat?: boolean;
}
/**
@ -1968,7 +1965,7 @@ export interface ParseTemplateOptions {
export function parseTemplate(
template: string, templateUrl: string, options: ParseTemplateOptions = {}):
{errors?: ParseError[], nodes: t.Node[], styleUrls: string[], styles: string[]} {
const {interpolationConfig, preserveWhitespaces, i18nLegacyMessageIdFormat} = options;
const {interpolationConfig, preserveWhitespaces, enableI18nLegacyMessageIdFormat} = options;
const bindingParser = makeBindingParser(interpolationConfig);
const htmlParser = new HtmlParser();
const parseResult = htmlParser.parse(
@ -1986,7 +1983,8 @@ export function parseTemplate(
// extraction process (ng xi18n) relies on a raw content to generate
// message ids
const i18nMetaVisitor = new I18nMetaVisitor(
interpolationConfig, /* keepI18nAttrs */ !preserveWhitespaces, i18nLegacyMessageIdFormat);
interpolationConfig, /* keepI18nAttrs */ !preserveWhitespaces,
enableI18nLegacyMessageIdFormat);
rootNodes = html.visitAll(i18nMetaVisitor, rootNodes);
if (!preserveWhitespaces) {