diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts index 0655cb75d5ce7..80844203aaddf 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts @@ -169,7 +169,7 @@ const verify = (input: string, output: string, extra: any = {}): void => { } }; -describe('i18n support in the view compiler', () => { +describe('i18n support in the template compiler', () => { describe('element attributes', () => { it('should add the meaning and description as JsDoc comments', () => { @@ -943,6 +943,24 @@ describe('i18n support in the view compiler', () => { verify(input, output, {exceptions}); }); + it('should ignore HTML comments within translated text', () => { + const input = ` +
Some text
+ `; + + const output = String.raw ` + var $I18N_0$; + if (ngI18nClosureMode) { + const $MSG_EXTERNAL_0$ = goog.getMsg("Some text"); + $I18N_0$ = $MSG_EXTERNAL_0$; + } + else { + $I18N_0$ = $localize \`Some text\`; + } + `; + verify(input, output); + }); + it('should properly escape quotes in content', () => { const input = `
Some text 'with single quotes', "with double quotes" and without quotes.
diff --git a/packages/compiler/src/render3/view/i18n/localize_utils.ts b/packages/compiler/src/render3/view/i18n/localize_utils.ts index a5ec3db8e6150..a512038e8fa39 100644 --- a/packages/compiler/src/render3/view/i18n/localize_utils.ts +++ b/packages/compiler/src/render3/view/i18n/localize_utils.ts @@ -44,7 +44,12 @@ class PlaceholderPiece extends MessagePiece { */ class LocalizeSerializerVisitor implements i18n.Visitor { visitText(text: i18n.Text, context: MessagePiece[]): any { - context.push(new LiteralPiece(text.value)); + if (context[context.length - 1] instanceof LiteralPiece) { + // Two literal pieces in a row means that there was some comment node in-between. + context[context.length - 1].text += text.value; + } else { + context.push(new LiteralPiece(text.value)); + } } visitContainer(container: i18n.Container, context: MessagePiece[]): any {