refactor: cleanup ICU message syntax
This commit is contained in:
parent
55dc0e4a5f
commit
778e6ad3b4
|
@ -155,27 +155,27 @@ export function main() {
|
||||||
() => { expect(extract('{count, plural, =0 {text}}')).toEqual([]); });
|
() => { expect(extract('{count, plural, =0 {text}}')).toEqual([]); });
|
||||||
|
|
||||||
it('should ignore nested ICU messages', () => {
|
it('should ignore nested ICU messages', () => {
|
||||||
expect(extract('<div i18n="m|d">{count, plural, =0 { {sex, gender, =m {m}} }}</div>'))
|
expect(extract('<div i18n="m|d">{count, plural, =0 { {sex, select, male {m}} }}</div>'))
|
||||||
.toEqual([
|
.toEqual([
|
||||||
[['{count, plural, =0 {[{sex, gender, =m {[m]}}, ]}}'], 'm', 'd'],
|
[['{count, plural, =0 {[{sex, select, male {[m]}}, ]}}'], 'm', 'd'],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore implicit elements in non translatable ICU messages', () => {
|
it('should ignore implicit elements in non translatable ICU messages', () => {
|
||||||
expect(
|
expect(
|
||||||
extract(
|
extract(
|
||||||
'<div i18n="m|d">{count, plural, =0 { {sex, gender, =m {<p>ignore</p>}} }}</div>',
|
'<div i18n="m|d">{count, plural, =0 { {sex, select, male {<p>ignore</p>}} }}</div>',
|
||||||
['p']))
|
['p']))
|
||||||
.toEqual([[
|
.toEqual([[
|
||||||
[
|
[
|
||||||
'{count, plural, =0 {[{sex, gender, =m {[<ph tag name="START_PARAGRAPH">ignore</ph name="CLOSE_PARAGRAPH">]}}, ]}}'
|
'{count, plural, =0 {[{sex, select, male {[<ph tag name="START_PARAGRAPH">ignore</ph name="CLOSE_PARAGRAPH">]}}, ]}}'
|
||||||
],
|
],
|
||||||
'm', 'd'
|
'm', 'd'
|
||||||
]]);
|
]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore implicit elements in non translatable ICU messages', () => {
|
it('should ignore implicit elements in non translatable ICU messages', () => {
|
||||||
expect(extract('{count, plural, =0 { {sex, gender, =m {<p>ignore</p>}} }}', ['p']))
|
expect(extract('{count, plural, =0 { {sex, select, male {<p>ignore</p>}} }}', ['p']))
|
||||||
.toEqual([]);
|
.toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -186,16 +186,16 @@ export function main() {
|
||||||
|
|
||||||
it('should not extract nested ICU messages', () => {
|
it('should not extract nested ICU messages', () => {
|
||||||
expect(_humanizeMessages(
|
expect(_humanizeMessages(
|
||||||
'<div i18n="m|d">b{count, plural, =0 {{sex, gender, =m {m}}}}a</div>'))
|
'<div i18n="m|d">b{count, plural, =0 {{sex, select, male {m}}}}a</div>'))
|
||||||
.toEqual([
|
.toEqual([
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
'b', '<ph icu name="ICU">{count, plural, =0 {[{sex, gender, =m {[m]}}]}}</ph>',
|
'b', '<ph icu name="ICU">{count, plural, =0 {[{sex, select, male {[m]}}]}}</ph>',
|
||||||
'a'
|
'a'
|
||||||
],
|
],
|
||||||
'm', 'd'
|
'm', 'd'
|
||||||
],
|
],
|
||||||
[['{count, plural, =0 {[{sex, gender, =m {[m]}}]}}'], '', ''],
|
[['{count, plural, =0 {[{sex, select, male {[m]}}]}}'], '', ''],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function main(): void {
|
||||||
<p i18n>translatable element <b>with placeholders</b> {{ interpolation}}</p>
|
<p i18n>translatable element <b>with placeholders</b> {{ interpolation}}</p>
|
||||||
<!-- i18n -->{ count, plural, =0 {<p>test</p>}}<!-- /i18n -->
|
<!-- i18n -->{ count, plural, =0 {<p>test</p>}}<!-- /i18n -->
|
||||||
<p i18n="m|d">foo</p>
|
<p i18n="m|d">foo</p>
|
||||||
<p i18n>{ count, plural, =0 { { sex, gender, other {<p>deeply nested</p>}} }}</p>`;
|
<p i18n>{ count, plural, =0 { { sex, select, other {<p>deeply nested</p>}} }}</p>`;
|
||||||
|
|
||||||
const XMB = `<?xml version="1.0" encoding="UTF-8" ?>
|
const XMB = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE messagebundle [
|
<!DOCTYPE messagebundle [
|
||||||
|
@ -46,7 +46,7 @@ export function main(): void {
|
||||||
<msg id="ec1d033f2436133c14ab038286c4f5df4697484a">translatable element <ph name="START_BOLD_TEXT"><ex><b></ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> <ph name="INTERPOLATION"/></msg>
|
<msg id="ec1d033f2436133c14ab038286c4f5df4697484a">translatable element <ph name="START_BOLD_TEXT"><ex><b></ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> <ph name="INTERPOLATION"/></msg>
|
||||||
<msg id="e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2">{ count, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg>
|
<msg id="e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2">{ count, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg>
|
||||||
<msg id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23" desc="d" meaning="m">foo</msg>
|
<msg id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23" desc="d" meaning="m">foo</msg>
|
||||||
<msg id="83dd87699b8c1779dd72277ef6e2d46ca58be042">{ count, plural, =0 {{ sex, gender, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg>
|
<msg id="0e16a673a5a7a135c9f7b957ec2c5c6f6ee6e2c4">{ count, plural, =0 {{ sex, select, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg>
|
||||||
</messagebundle>
|
</messagebundle>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {escapeRegExp} from '@angular/core/src/facade/lang';
|
import {escapeRegExp} from '@angular/core/src/facade/lang';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
|
|
||||||
|
|
||||||
import {MessageBundle} from '../../../src/i18n/message_bundle';
|
import {MessageBundle} from '../../../src/i18n/message_bundle';
|
||||||
import {Xtb} from '../../../src/i18n/serializers/xtb';
|
import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||||
|
@ -101,22 +100,22 @@ export function main(): void {
|
||||||
<div i18n>foo <b>bar</b> {{ a + b }}</div>
|
<div i18n>foo <b>bar</b> {{ a + b }}</div>
|
||||||
<div i18n>{ count, plural, =0 {<p>bar</p>}}</div>
|
<div i18n>{ count, plural, =0 {<p>bar</p>}}</div>
|
||||||
<div i18n="m|d">foo</div>
|
<div i18n="m|d">foo</div>
|
||||||
<div i18n>{ count, plural, =0 {{ sex, gender, other {<p>bar</p>}} }}</div>`;
|
<div i18n>{ count, plural, =0 {{ sex, select, other {<p>bar</p>}} }}</div>`;
|
||||||
|
|
||||||
const XTB = `<?xml version="1.0" encoding="UTF-8" ?>
|
const XTB = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<translationbundle>
|
<translationbundle>
|
||||||
<translation id="7103b4b13b616270a0044efade97d8b4f96f2ca6"><ph name="INTERPOLATION"/><ph name="START_BOLD_TEXT"/>rab<ph name="CLOSE_BOLD_TEXT"/> oof</translation>
|
<translation id="7103b4b13b616270a0044efade97d8b4f96f2ca6"><ph name="INTERPOLATION"/><ph name="START_BOLD_TEXT"/>rab<ph name="CLOSE_BOLD_TEXT"/> oof</translation>
|
||||||
<translation id="fc92b9b781194a02ab773129c8c5a7fc0735efd7">{ count, plural, =1 {<ph name="START_PARAGRAPH"/>rab<ph name="CLOSE_PARAGRAPH"/>}}</translation>
|
<translation id="fc92b9b781194a02ab773129c8c5a7fc0735efd7">{ count, plural, =1 {<ph name="START_PARAGRAPH"/>rab<ph name="CLOSE_PARAGRAPH"/>}}</translation>
|
||||||
<translation id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23">oof</translation>
|
<translation id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23">oof</translation>
|
||||||
<translation id="e3bf2d706c3da16ce05658e07f62f0519f7c561c">{ count, plural, =1 {{ sex, gender, male {<ph name="START_PARAGRAPH"/>rab<ph name="CLOSE_PARAGRAPH"/>}} }}</translation>
|
<translation id="8fb569d3dd83e92eff2551b24f5290d3035ce61b">{ count, plural, =1 {{ sex, select, other {<ph name="START_PARAGRAPH"/>rab<ph name="CLOSE_PARAGRAPH"/>}} }}</translation>
|
||||||
</translationbundle>`;
|
</translationbundle>`;
|
||||||
|
|
||||||
expect(loadAsText(HTML, XTB)).toEqual({
|
expect(loadAsText(HTML, XTB)).toEqual({
|
||||||
'7103b4b13b616270a0044efade97d8b4f96f2ca6': `{{ a + b }}<b>rab</b> oof`,
|
'7103b4b13b616270a0044efade97d8b4f96f2ca6': `{{ a + b }}<b>rab</b> oof`,
|
||||||
'fc92b9b781194a02ab773129c8c5a7fc0735efd7': `{ count, plural, =1 {<p>rab</p>}}`,
|
'fc92b9b781194a02ab773129c8c5a7fc0735efd7': `{ count, plural, =1 {<p>rab</p>}}`,
|
||||||
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': `oof`,
|
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': `oof`,
|
||||||
'e3bf2d706c3da16ce05658e07f62f0519f7c561c':
|
'8fb569d3dd83e92eff2551b24f5290d3035ce61b':
|
||||||
`{ count, plural, =1 {{ sex, gender, male {<p>rab</p>}} }}`,
|
`{ count, plural, =1 {{ sex, select, other {<p>rab</p>}} }}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export function main() {
|
||||||
<span>{{ interpolation }}</span>
|
<span>{{ interpolation }}</span>
|
||||||
<!--comment-->
|
<!--comment-->
|
||||||
<p expansion="true">
|
<p expansion="true">
|
||||||
{number, plural, =0 {{sex, gender, other {<b>?</b>}}}}
|
{number, plural, =0 {{sex, select, other {<b>?</b>}}}}
|
||||||
</p>
|
</p>
|
||||||
</div>`;
|
</div>`;
|
||||||
const ast = parser.parse(html, 'url', true);
|
const ast = parser.parse(html, 'url', true);
|
||||||
|
|
|
@ -306,7 +306,7 @@ export function main() {
|
||||||
|
|
||||||
it('should parse out nested expansion forms', () => {
|
it('should parse out nested expansion forms', () => {
|
||||||
let parsed = parser.parse(
|
let parsed = parser.parse(
|
||||||
`{messages.length, plural, =0 { {p.gender, gender, =m {m}} }}`, 'TestComp', true);
|
`{messages.length, plural, =0 { {p.gender, select, male {m}} }}`, 'TestComp', true);
|
||||||
expect(humanizeDom(parsed)).toEqual([
|
expect(humanizeDom(parsed)).toEqual([
|
||||||
[html.Expansion, 'messages.length', 'plural', 0],
|
[html.Expansion, 'messages.length', 'plural', 0],
|
||||||
[html.ExpansionCase, '=0', 1],
|
[html.ExpansionCase, '=0', 1],
|
||||||
|
@ -315,8 +315,8 @@ export function main() {
|
||||||
let firstCase = (<any>parsed.rootNodes[0]).cases[0];
|
let firstCase = (<any>parsed.rootNodes[0]).cases[0];
|
||||||
|
|
||||||
expect(humanizeDom(new ParseTreeResult(firstCase.expression, []))).toEqual([
|
expect(humanizeDom(new ParseTreeResult(firstCase.expression, []))).toEqual([
|
||||||
[html.Expansion, 'p.gender', 'gender', 0],
|
[html.Expansion, 'p.gender', 'select', 0],
|
||||||
[html.ExpansionCase, '=m', 1],
|
[html.ExpansionCase, 'male', 1],
|
||||||
[html.Text, ' ', 0],
|
[html.Text, ' ', 0],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,7 +37,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle nested expansion forms', () => {
|
it('should handle nested expansion forms', () => {
|
||||||
const res = expand(`{messages.length, plural, =0 { {p.gender, gender, =m {m}} }}`);
|
const res = expand(`{messages.length, plural, =0 { {p.gender, select, =m {m}} }}`);
|
||||||
|
|
||||||
expect(humanizeNodes(res.nodes)).toEqual([
|
expect(humanizeNodes(res.nodes)).toEqual([
|
||||||
[html.Element, 'ng-container', 0],
|
[html.Element, 'ng-container', 0],
|
||||||
|
|
|
@ -1787,7 +1787,7 @@ The pipe 'test' could not be found ("[ERROR ->]{{a | test}}"): TestComp@0:0`);
|
||||||
const shortForm = '{ count, plural, =0 {small} many {big} }';
|
const shortForm = '{ count, plural, =0 {small} many {big} }';
|
||||||
const expandedForm = '<ng-container [ngPlural]="count">' +
|
const expandedForm = '<ng-container [ngPlural]="count">' +
|
||||||
'<template ngPluralCase="=0">small</template>' +
|
'<template ngPluralCase="=0">small</template>' +
|
||||||
'<template ngPluralCase="many">big</template>' + i
|
'<template ngPluralCase="many">big</template>' +
|
||||||
'</ng-container>';
|
'</ng-container>';
|
||||||
|
|
||||||
expect(humanizeTplAst(parse(shortForm, [
|
expect(humanizeTplAst(parse(shortForm, [
|
||||||
|
|
Loading…
Reference in New Issue