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
This commit is contained in:
Andrew Kushnir
2020-06-29 17:50:21 -07:00
committed by Alex Rickabaugh
parent d148fdccf2
commit aed6b131bb
3 changed files with 62 additions and 1 deletions

View File

@ -3661,6 +3661,39 @@ describe('i18n support in the template compiler', () => {
verify(input, output);
});
it('should produce proper messages when `select` or `plural` keywords have spaces after them',
() => {
const input = `
<div i18n>
{count, select , 1 {one} other {more than one}}
{count, plural , =1 {one} other {more than one}}
</div>
`;
const output = String.raw`
var $I18N_1$;
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) {
const $MSG_EXTERNAL_199763560911211963$$APP_SPEC_TS_2$ = goog.getMsg("{VAR_SELECT , select , 1 {one} other {more than one}}");
$I18N_1$ = $MSG_EXTERNAL_199763560911211963$$APP_SPEC_TS_2$;
}
else {
$I18N_1$ = $localize \`{VAR_SELECT , select , 1 {one} other {more than one}}\`;
}
$I18N_1$ = i0.ɵɵi18nPostprocess($I18N_1$, { "VAR_SELECT": "\uFFFD0\uFFFD" });
var $I18N_3$;
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) {
const $MSG_EXTERNAL_3383986062053865025$$APP_SPEC_TS_4$ = goog.getMsg("{VAR_PLURAL , plural , =1 {one} other {more than one}}");
$I18N_3$ = $MSG_EXTERNAL_3383986062053865025$$APP_SPEC_TS_4$;
}
else {
$I18N_3$ = $localize \`{VAR_PLURAL , plural , =1 {one} other {more than one}}\`;
}
$I18N_3$ = i0.ɵɵi18nPostprocess($I18N_3$, { "VAR_PLURAL": "\uFFFD1\uFFFD" });
`;
verify(input, output);
});
});
describe('$localize legacy message ids', () => {