-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): Rework how ICU placeholders are handled (#53643)
The way we were handling ICU placeholders was not compatible with using interpolations on attributes of elements inside the ICU. This change refactors the handling of ICU placeholders and unifies the way expression and tag placeholders work inside ICUs. The new approach modifies the ingest logic to add the placeholder on to the TextOp rather than the TextInterpolationOp. This is because, in ICUs, we may need multiple i18n expressions created from the interpolation expressions to roll up into the same placeholder. ICUs essentially do the interpolation at compile time, combining the static strings with special placeholder strings that represent the expression values. PR Close #53643
- Loading branch information
Showing
16 changed files
with
308 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/attribute_interpolation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
consts: () => { | ||
let $i18n_1$; | ||
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) { | ||
/** | ||
* @suppress {msgDescriptions} | ||
*/ | ||
const $MSG_EXTERNAL_6301050568345677976__ATTRIBUTE_INTERPOLATION_TS_2$ = goog.getMsg("{VAR_SELECT, select, other {{START_TAG_SPAN}foo{CLOSE_TAG_SPAN}}}"); | ||
$i18n_1$ = $MSG_EXTERNAL_6301050568345677976__ATTRIBUTE_INTERPOLATION_TS_2$; | ||
} else { | ||
$i18n_1$ = $localize`{VAR_SELECT, select, other {{START_TAG_SPAN}foo{CLOSE_TAG_SPAN}}}`; | ||
} | ||
$i18n_1$ = i0.ɵɵi18nPostprocess($i18n_1$, { | ||
"CLOSE_TAG_SPAN": "</span>", | ||
"START_TAG_SPAN": "<span title=\"\uFFFD1\uFFFD-\uFFFD2\uFFFD\">", | ||
"VAR_SELECT": "\uFFFD0\uFFFD" | ||
}); | ||
let $i18n_3$; | ||
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) { | ||
/** | ||
* @suppress {msgDescriptions} | ||
*/ | ||
const $MSG_EXTERNAL_369205108016154659__ATTRIBUTE_INTERPOLATION_TS_4$ = goog.getMsg("{VAR_SELECT, select, other {{INTERPOLATION}-{INTERPOLATION}}}"); | ||
$i18n_3$ = $MSG_EXTERNAL_369205108016154659__ATTRIBUTE_INTERPOLATION_TS_4$; | ||
} else { | ||
$i18n_3$ = $localize`{VAR_SELECT, select, other {{INTERPOLATION}-{INTERPOLATION}}}`; | ||
} | ||
$i18n_3$ = i0.ɵɵi18nPostprocess($i18n_3$, { | ||
"INTERPOLATION": "\uFFFD4\uFFFD", | ||
"VAR_SELECT": "\uFFFD3\uFFFD" | ||
}); | ||
let $i18n_0$; | ||
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) { | ||
/** | ||
* @suppress {msgDescriptions} | ||
*/ | ||
const $MSG_EXTERNAL_6009429127580785009__ATTRIBUTE_INTERPOLATION_TS_5$ = goog.getMsg( | ||
"{$startTagSpan}{$closeTagSpan}{$startTagSpan_1}{$icu}{$closeTagSpan}{$startTagSpan_1}{$icu_1}{$closeTagSpan}", | ||
{ | ||
"closeTagSpan": "[\uFFFD/#2\uFFFD|\uFFFD/#3\uFFFD|\uFFFD/#4\uFFFD]", | ||
"icu": $i18n_1$, | ||
"icu_1": $i18n_3$, | ||
"startTagSpan": "\uFFFD#2\uFFFD", | ||
"startTagSpan_1": "[\uFFFD#3\uFFFD|\uFFFD#4\uFFFD]" | ||
}, { | ||
original_code: { | ||
"closeTagSpan": "</span>", | ||
"icu": "{foo, select, other {<span title=\"{{foo}}-{{foo}}\">foo</span>}}", | ||
"icu_1": "{foo, select, other {{{foo}}-{{foo}}}}", | ||
"startTagSpan": "<span title=\"{{foo}}-{{foo}}\">", | ||
"startTagSpan_1": "<span>" | ||
} | ||
}); | ||
$i18n_0$ = $MSG_EXTERNAL_6009429127580785009__ATTRIBUTE_INTERPOLATION_TS_5$; | ||
} else { | ||
$i18n_0$ = $localize`${"\uFFFD#2\uFFFD"}:START_TAG_SPAN:${"[\uFFFD/#2\uFFFD|\uFFFD/#3\uFFFD|\uFFFD/#4\uFFFD]"}:CLOSE_TAG_SPAN:${"[\uFFFD#3\uFFFD|\uFFFD#4\uFFFD]"}:START_TAG_SPAN_1:${$i18n_1$}:ICU@@6051755734147382484:${"[\uFFFD/#2\uFFFD|\uFFFD/#3\uFFFD|\uFFFD/#4\uFFFD]"}:CLOSE_TAG_SPAN:${"[\uFFFD#3\uFFFD|\uFFFD#4\uFFFD]"}:START_TAG_SPAN_1:${$i18n_3$}:ICU_1@@7593934392904803263:${"[\uFFFD/#2\uFFFD|\uFFFD/#3\uFFFD|\uFFFD/#4\uFFFD]"}:CLOSE_TAG_SPAN:`; | ||
} | ||
$i18n_0$ = i0.ɵɵi18nPostprocess($i18n_0$); | ||
return [$i18n_0$, [3, "title"]]; | ||
}, | ||
template: function MyComponent_Template(rf, ctx) { | ||
if (rf & 1) { | ||
i0.ɵɵelementStart(0, "div"); | ||
i0.ɵɵi18nStart(1, 0); | ||
i0.ɵɵelement(2, "span", 1)(3, "span")(4, "span"); | ||
i0.ɵɵi18nEnd(); | ||
i0.ɵɵelementEnd(); | ||
} | ||
if (rf & 2) { | ||
i0.ɵɵadvance(2); | ||
i0.ɵɵpropertyInterpolate2("title", "", ctx.foo, "-", ctx.foo, ""); | ||
i0.ɵɵadvance(2); | ||
i0.ɵɵi18nExp(ctx.foo)(ctx.foo)(ctx.foo)(ctx.foo)(ctx.foo); | ||
i0.ɵɵi18nApply(1); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/attribute_interpolation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'my-comp', | ||
standalone: true, | ||
template: ` | ||
<div i18n> | ||
<span title="{{foo}}-{{foo}}"></span> | ||
<span>{foo, select, other {<span title="{{foo}}-{{foo}}">foo</span>}}</span> | ||
<span>{foo, select, other {{{foo}}-{{foo}}}}</span> | ||
</div> | ||
` | ||
}) | ||
export class MyComponent { | ||
foo: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.