diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index 205433cf138db..04888681e57ee 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -701,7 +701,8 @@ function i18nEndFirstPass(tView: TView, lView: LView) { } // Check if an element has any local refs and skip them const tNode = getTNode(tView, index); - if (tNode && (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) && + if (tNode && (tNode.type === TNodeType.Container || tNode.type === TNodeType.Element || + tNode.type === TNodeType.ElementContainer) && tNode.localNames !== null) { // Divide by 2 to get the number of local refs, // since they are stored as an array that also includes directive indexes, diff --git a/packages/core/test/acceptance/i18n_spec.ts b/packages/core/test/acceptance/i18n_spec.ts index 7e52d460be88f..37712a7aea50d 100644 --- a/packages/core/test/acceptance/i18n_spec.ts +++ b/packages/core/test/acceptance/i18n_spec.ts @@ -299,19 +299,28 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { [computeMsgId( '{$START_TAG_NG_CONTAINER} One {$CLOSE_TAG_NG_CONTAINER}' + '{$START_TAG_DIV} Two {$CLOSE_TAG_DIV}' + - '{$START_TAG_SPAN} Three {$CLOSE_TAG_SPAN}')]: + '{$START_TAG_SPAN} Three {$CLOSE_TAG_SPAN}' + + '{$START_TAG_NG_TEMPLATE} Four {$CLOSE_TAG_NG_TEMPLATE}' + + '{$START_TAG_NG_CONTAINER_1}{$CLOSE_TAG_NG_CONTAINER}')]: + '{$START_TAG_NG_CONTAINER} Une {$CLOSE_TAG_NG_CONTAINER}' + '{$START_TAG_DIV} Deux {$CLOSE_TAG_DIV}' + - '{$START_TAG_SPAN} Trois {$CLOSE_TAG_SPAN}' + '{$START_TAG_SPAN} Trois {$CLOSE_TAG_SPAN}' + + '{$START_TAG_NG_TEMPLATE} Quatre {$CLOSE_TAG_NG_TEMPLATE}' + + '{$START_TAG_NG_CONTAINER_1}{$CLOSE_TAG_NG_CONTAINER}' + }); const fixture = initWithTemplate(AppComp, `
One
Two
Three + + Four +
`); - expect(fixture.nativeElement.textContent).toBe(' Une Deux Trois '); + expect(fixture.nativeElement.textContent).toBe(' Une Deux Trois Quatre '); }); it('should handle local refs correctly in case an element is removed in translation', () => {