Skip to content

Commit a3a5429

Browse files
ocombemhevery
authored andcommitted
fix(compiler): allow numbers for ICU message cases in lexer (#18095)
Closes #18095 Fixes #17799
1 parent 15a3e2d commit a3a5429

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

packages/compiler/src/ml_parser/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ function isExpansionFormStart(
684684
}
685685

686686
function isExpansionCaseStart(peek: number): boolean {
687-
return peek === chars.$EQ || chars.isAsciiLetter(peek);
687+
return peek === chars.$EQ || chars.isAsciiLetter(peek) || chars.isDigit(peek);
688688
}
689689

690690
function compareCharCodeCaseInsensitive(code1: number, code2: number): boolean {

packages/compiler/test/i18n/integration_common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export function validateHtml(
7878
cmp.sex = 'f';
7979
tb.detectChanges();
8080
expect(el.query(By.css('#i18n-8')).nativeElement).toHaveText('femme');
81+
cmp.sex = '0';
82+
tb.detectChanges();
83+
expect(el.query(By.css('#i18n-8')).nativeElement).toHaveText('autre');
8184

8285
cmp.count = 123;
8386
tb.detectChanges();
@@ -121,7 +124,7 @@ export const HTML = `
121124
<div i18n id="i18n-7">{count, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>}}</div>
122125
123126
<div i18n id="i18n-8">
124-
{sex, select, m {male} f {female}}
127+
{sex, select, m {male} f {female} 0 {other}}
125128
</div>
126129
<div i18n id="i18n-8b">
127130
{sexB, select, m {male} f {female}}

packages/compiler/test/i18n/integration_xliff_spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ const XLIFF_TOMERGE = `
8585
<source>{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<x id="START_BOLD_TEXT" ctype="x-b"/>many<x id="CLOSE_BOLD_TEXT" ctype="x-b"/>} }</source>
8686
<target>{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<x id="START_BOLD_TEXT" ctype="x-b"/>beaucoup<x id="CLOSE_BOLD_TEXT" ctype="x-b"/>} }</target>
8787
</trans-unit>
88-
<trans-unit id="85ef51de59fe5a8d13fba977b6689f164420c8ca" datatype="html">
88+
<trans-unit id="ba9106fca6e4e33a9b703a8c1927e2d1794dd9ff" datatype="html">
8989
<source>
9090
<x id="ICU"/>
9191
</source>
9292
<target><x id="ICU"/></target>
9393
</trans-unit>
94-
<trans-unit id="c0ca5e58fe954d528bbfa516007a5a11690a7e99" datatype="html">
95-
<source>{VAR_SELECT, select, m {male} f {female} }</source>
96-
<target>{VAR_SELECT, select, m {homme} f {femme} }</target>
94+
<trans-unit id="7b7916d063ebaafcd2e9dcdf697b5e184fcb8099" datatype="html">
95+
<source>{VAR_SELECT, select, 0 {other} m {male} f {female} }</source>
96+
<target>{VAR_SELECT, select, 0 {autre} m {homme} f {femme}}</target>
9797
</trans-unit>
9898
<trans-unit id="078b7089573c5f66a2f78dce0adaa55e6715beb1" datatype="html">
9999
<source>
@@ -123,12 +123,12 @@ const XLIFF_TOMERGE = `
123123
</trans-unit>
124124
<trans-unit id="eee74a5be8a75881a4785905bd8302a71f7d9f75" datatype="html">
125125
<source>
126-
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Markers in html comments<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
126+
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Markers in html comments<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
127127
<x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
128128
<x id="START_TAG_DIV_1" ctype="x-div"/><x id="ICU"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
129129
</source>
130130
<target>
131-
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Balises dans les commentaires html<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
131+
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Balises dans les commentaires html<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
132132
<x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
133133
<x id="START_TAG_DIV_1" ctype="x-div"/><x id="ICU"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
134134
</target>
@@ -218,7 +218,7 @@ const XLIFF_EXTRACTED = `
218218
<context context-type="linenumber">36</context>
219219
</context-group>
220220
</trans-unit>
221-
<trans-unit id="85ef51de59fe5a8d13fba977b6689f164420c8ca" datatype="html">
221+
<trans-unit id="ba9106fca6e4e33a9b703a8c1927e2d1794dd9ff" datatype="html">
222222
<source>
223223
<x id="ICU"/>
224224
</source>
@@ -227,8 +227,8 @@ const XLIFF_EXTRACTED = `
227227
<context context-type="linenumber">21</context>
228228
</context-group>
229229
</trans-unit>
230-
<trans-unit id="c0ca5e58fe954d528bbfa516007a5a11690a7e99" datatype="html">
231-
<source>{VAR_SELECT, select, m {male} f {female} }</source>
230+
<trans-unit id="7b7916d063ebaafcd2e9dcdf697b5e184fcb8099" datatype="html">
231+
<source>{VAR_SELECT, select, 0 {other} m {male} f {female} }</source>
232232
<context-group purpose="location">
233233
<context context-type="sourcefile">file.ts</context>
234234
<context context-type="linenumber">22</context>
@@ -284,7 +284,7 @@ const XLIFF_EXTRACTED = `
284284
</trans-unit>
285285
<trans-unit id="eee74a5be8a75881a4785905bd8302a71f7d9f75" datatype="html">
286286
<source>
287-
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Markers in html comments<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
287+
<x id="START_HEADING_LEVEL1" ctype="x-h1"/>Markers in html comments<x id="CLOSE_HEADING_LEVEL1" ctype="x-h1"/>
288288
<x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
289289
<x id="START_TAG_DIV_1" ctype="x-div"/><x id="ICU"/><x id="CLOSE_TAG_DIV" ctype="x-div"/>
290290
</source>

packages/compiler/test/i18n/integration_xmb_xtb_spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const XTB = `
6464
<translation id="5525133077318024839">sur des balises non traductibles</translation>
6565
<translation id="8670732454866344690">sur des balises traductibles</translation>
6666
<translation id="4593805537723189714">{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<ph name="START_BOLD_TEXT"/>beaucoup<ph name="CLOSE_BOLD_TEXT"/>}}</translation>
67+
<translation id="4360321700965841752"><ph name="ICU"/></translation>
68+
<translation id="5460933846928880074">{VAR_SELECT, select, 0 {autre} m {homme} f {femme} }</translation>
6769
<translation id="1746565782635215"><ph name="ICU"/></translation>
6870
<translation id="5868084092545682515">{VAR_SELECT, select, m {homme} f {femme}}</translation>
6971
<translation id="4851788426695310455"><ph name="INTERPOLATION"/></translation>
@@ -84,17 +86,21 @@ const XTB = `
8486
<translation id="5339604010413301604"><ph name="MAP_NAME"><ex>MAP_NAME</ex></ph></translation>
8587
</translationbundle>`;
8688

87-
const XMB = ` <msg id="615790887472569365"><source>file.ts:3</source>i18n attribute on tags</msg>
89+
const XMB = `<msg id="615790887472569365"><source>file.ts:3</source>i18n attribute on tags</msg>
8890
<msg id="3707494640264351337"><source>file.ts:5</source>nested</msg>
8991
<msg id="5539162898278769904" meaning="different meaning"><source>file.ts:7</source>nested</msg>
9092
<msg id="3780349238193953556"><source>file.ts:9</source><source>file.ts:10</source><ph name="START_ITALIC_TEXT"><ex>&lt;i&gt;</ex></ph>with placeholders<ph name="CLOSE_ITALIC_TEXT"><ex>&lt;/i&gt;</ex></ph></msg>
9193
<msg id="5525133077318024839"><source>file.ts:13</source>on not translatable node</msg>
9294
<msg id="8670732454866344690"><source>file.ts:14</source>on translatable node</msg>
9395
<msg id="4593805537723189714"><source>file.ts:19</source><source>file.ts:36</source>{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<ph name="START_BOLD_TEXT"><ex>&lt;b&gt;</ex></ph>many<ph name="CLOSE_BOLD_TEXT"><ex>&lt;/b&gt;</ex></ph>} }</msg>
94-
<msg id="1746565782635215"><source>file.ts:21,23</source><source>file.ts:24,26</source>
96+
<msg id="4360321700965841752"><source>file.ts:21,23</source>
9597
<ph name="ICU"><ex>ICU</ex></ph>
9698
</msg>
97-
<msg id="5868084092545682515"><source>file.ts:22</source><source>file.ts:25</source>{VAR_SELECT, select, m {male} f {female} }</msg>
99+
<msg id="5460933846928880074"><source>file.ts:22</source>{VAR_SELECT, select, 0 {other} m {male} f {female} }</msg>
100+
<msg id="1746565782635215"><source>file.ts:24,26</source>
101+
<ph name="ICU"><ex>ICU</ex></ph>
102+
</msg>
103+
<msg id="5868084092545682515"><source>file.ts:25</source>{VAR_SELECT, select, m {male} f {female} }</msg>
98104
<msg id="4851788426695310455"><source>file.ts:28</source><ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph></msg>
99105
<msg id="9013357158046221374"><source>file.ts:29</source>sex = <ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph></msg>
100106
<msg id="8324617391167353662"><source>file.ts:30</source><ph name="CUSTOM_NAME"><ex>CUSTOM_NAME</ex></ph></msg>

packages/compiler/test/ml_parser/html_parser_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ export function main() {
363363
]);
364364
});
365365

366+
it('should support ICU expressions with cases that contain numbers', () => {
367+
const p = parser.parse(`{sex, select, male {m} female {f} 0 {other}}`, 'TestComp', true);
368+
expect(p.errors.length).toEqual(0);
369+
});
370+
366371
it('should error when expansion case is not closed', () => {
367372
const p = parser.parse(`{messages.length, plural, =0 {one`, 'TestComp', true);
368373
expect(humanizeErrors(p.errors)).toEqual([

0 commit comments

Comments
 (0)