feat(ivy): i18n - render legacy message ids in $localize if requested (#32937)

The `$localize` library uses a new message digest function for
computing message ids. This means that translations in legacy
translation files will no longer match the message ids in the code
and so will not be translated.

This commit adds the ability to specify the format of your legacy
translation files, so that the appropriate message id can be rendered
in the `$localize` tagged strings. This results in larger code size
and requires that all translations are in the legacy format.

Going forward the developer should migrate their translation files
to use the new message id format.

PR Close #32937
This commit is contained in:
Pete Bacon Darwin
2019-10-01 14:58:49 +01:00
committed by atscott
parent fc28b266cd
commit bcbf3e4123
11 changed files with 148 additions and 22 deletions

View File

@ -1905,6 +1905,19 @@ export interface ParseTemplateOptions {
* included in source-map segments. A common example is whitespace.
*/
leadingTriviaChars?: string[];
/**
* Render `$localize` message ids with the specified legacy format (xlf, xlf2 or xmb).
*
* 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.
*
* @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.
*/
i18nLegacyMessageIdFormat?: string;
}
/**
@ -1917,7 +1930,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} = options;
const {interpolationConfig, preserveWhitespaces, i18nLegacyMessageIdFormat} = options;
const bindingParser = makeBindingParser(interpolationConfig);
const htmlParser = new HtmlParser();
const parseResult = htmlParser.parse(
@ -1934,8 +1947,9 @@ export function parseTemplate(
// before we run whitespace removal process, because existing i18n
// extraction process (ng xi18n) relies on a raw content to generate
// message ids
rootNodes =
html.visitAll(new I18nMetaVisitor(interpolationConfig, !preserveWhitespaces), rootNodes);
rootNodes = html.visitAll(
new I18nMetaVisitor(interpolationConfig, !preserveWhitespaces, i18nLegacyMessageIdFormat),
rootNodes);
if (!preserveWhitespaces) {
rootNodes = html.visitAll(new WhitespaceVisitor(), rootNodes);