fix(core): handle spaces after `select` and `plural` ICU keywords (#3… · angular/angular@aed6b13 · GitHub
Skip to content

Commit aed6b13

Browse files
AndrewKushniralxhub
authored andcommitted
fix(core): handle spaces after select and plural ICU keywords (#37866)
Currently when the `plural` or `select` keywords in an ICU contain trailing spaces (e.g. `{count, select , ...}`), these spaces are also included into the key names in ICU vars (e.g. "VAR_SELECT "). These trailing spaces are not desirable, since they will later be converted into `_` symbols while normalizing placeholder names, thus causing mismatches at runtime (i.e. placeholder will not be replaced with the correct value). This commit updates the code to trim these spaces while generating an object with placeholders, to make sure the runtime logic can replace these placeholders with the right values. PR Close #37866
1 parent d148fdc commit aed6b13

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts‎

Lines changed: 33 additions & 0 deletions

‎packages/compiler/src/render3/r3_template_transform.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,20 @@ class HtmlAstToIvyAst implements html.Visitor {
273273
const value = message.placeholders[key];
274274
if (key.startsWith(I18N_ICU_VAR_PREFIX)) {
275275
const config = this.bindingParser.interpolationConfig;
276+
276277
// ICU expression is a plain string, not wrapped into start
277278
// and end tags, so we wrap it before passing to binding parser
278279
const wrapped = `${config.start}${value}${config.end}`;
279-
vars[key] = this._visitTextWithInterpolation(wrapped, expansion.sourceSpan) as t.BoundText;
280+
281+
// Currently when the `plural` or `select` keywords in an ICU contain trailing spaces (e.g.
282+
// `{count, select , ...}`), these spaces are also included into the key names in ICU vars
283+
// (e.g. "VAR_SELECT "). These trailing spaces are not desirable, since they will later be
284+
// converted into `_` symbols while normalizing placeholder names, which might lead to
285+
// mismatches at runtime (i.e. placeholder will not be replaced with the correct value).
286+
const formattedKey = key.trim();
287+
288+
vars[formattedKey] =
289+
this._visitTextWithInterpolation(wrapped, expansion.sourceSpan) as t.BoundText;
280290
} else {
281291
placeholders[key] = this._visitTextWithInterpolation(value, expansion.sourceSpan);
282292
}

‎packages/core/test/acceptance/i18n_spec.ts‎

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)