Skip to content

Commit 19ae226

Browse files
filipesilvaclydin
authored andcommitted
test: add pluralization tests for non-localize i18n
1 parent ea37808 commit 19ae226

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

tests/legacy-cli/e2e/tests/build/aot/aot-i18n.ts

+42-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,26 @@ export default async function () {
1414

1515
// Set configurations for each locale.
1616
const langTranslations = [
17-
{ lang: 'en', translation: 'Hello i18n!', outputPath: enDir },
18-
{ lang: 'fr', translation: 'Bonjour i18n!', outputPath: frDist },
19-
{ lang: 'de', translation: 'Hallo i18n!', outputPath: deDir },
17+
{
18+
lang: 'en', outputPath: enDir,
19+
translation: { hello: 'Hello i18n!', plural: 'Updated 3 minutes ago' },
20+
},
21+
{
22+
lang: 'fr', outputPath: frDist,
23+
translation: { hello: 'Bonjour i18n!', plural: 'Mis à jour Il y a 3 minutes' },
24+
pluralTargets: {
25+
text: '<target>Mis à jour <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target>',
26+
interpolation: '<target>{VAR_PLURAL, plural, =0 {juste maintenant} =1 {il y a une minute} other {Il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes} }</target>',
27+
},
28+
},
29+
{
30+
lang: 'de', outputPath: deDir,
31+
translation: { hello: 'Hallo i18n!', plural: 'Aktualisiert vor 3 Minuten' },
32+
pluralTargets: {
33+
text: '<target>Aktualisiert <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target>',
34+
interpolation: '<target>{VAR_PLURAL, plural, =0 {gerade jetzt} =1 {vor einer Minute} other {vor <x id="INTERPOLATION" equiv-text="{{minutes}}"/> Minuten} }</target>',
35+
},
36+
},
2037
];
2138

2239
await updateJsonFile('angular.json', workspaceJson => {
@@ -61,7 +78,12 @@ export default async function () {
6178
describe('workspace-project App', () => {
6279
it('should display welcome message', () => {
6380
browser.get(browser.baseUrl);
64-
expect(element(by.css('h1')).getText()).toEqual('${translation}');
81+
expect(element(by.css('h1')).getText()).toEqual('${translation.hello}');
82+
});
83+
84+
it('should display pluralized message', () => {
85+
browser.get(browser.baseUrl);
86+
expect(element(by.css('h2')).getText()).toEqual('${translation.plural}');
6587
});
6688
6789
afterEach(async () => {
@@ -75,29 +97,38 @@ export default async function () {
7597
`);
7698
}
7799

78-
// Add a translatable element.
100+
// Add translatable elements.
79101
await writeFile('src/app/app.component.html',
80-
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>');
102+
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>\n' +
103+
'<h2 i18n>Updated {minutes, plural, =0 {just now} =1 {one minute ago} other {{{minutes}} minutes ago}}</h2>');
104+
await replaceInFile('src/app/app.component.ts', `title = 'latest-app'`, 'minutes = 3');
81105

82106
// Extract the translation messages and copy them for each language.
83107
await ng('xi18n', '--output-path=src/locale');
84108
await expectFileToExist('src/locale/messages.xlf');
85109
await expectFileToMatch('src/locale/messages.xlf', `source-language="en-US"`);
86110
await expectFileToMatch('src/locale/messages.xlf', `An introduction header for this sample`);
87111

88-
for (const { lang, translation } of langTranslations) {
112+
const helloSrc = '<source>Hello i18n!</source>';
113+
const pluralTextSrc = '<source>Updated <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source>';
114+
const pluralInterpolationSrc = '<source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source>';
115+
for (const { lang, translation, pluralTargets } of langTranslations) {
89116
if (lang != 'en') {
90117
await copyFile('src/locale/messages.xlf', `src/locale/messages.${lang}.xlf`);
91-
await replaceInFile(`src/locale/messages.${lang}.xlf`, '<source>Hello i18n!</source>',
92-
`<source>Hello i18n!</source>\n<target>${translation}</target>`);
118+
await replaceInFile(`src/locale/messages.${lang}.xlf`, helloSrc,
119+
`${helloSrc}\n<target>${translation.hello}</target>`);
120+
await replaceInFile(`src/locale/messages.${lang}.xlf`, pluralTextSrc,
121+
`${pluralTextSrc}\n${pluralTargets.text}`);
122+
await replaceInFile(`src/locale/messages.${lang}.xlf`, pluralInterpolationSrc,
123+
`${pluralInterpolationSrc}\n${pluralTargets.interpolation}`);
93124
}
94125
}
95126

96127
for (const { lang, translation, outputPath } of langTranslations) {
97128
// Build each locale and verify the output.
98129
await ng('build', `--configuration=${lang}`);
99-
await expectFileToMatch(`${outputPath}/main-es5.js`, translation);
100-
await expectFileToMatch(`${outputPath}/main-es2015.js`, translation);
130+
await expectFileToMatch(`${outputPath}/main-es5.js`, translation.hello);
131+
await expectFileToMatch(`${outputPath}/main-es2015.js`, translation.hello);
101132

102133
// E2E to verify the output runs and is correct.
103134
if (getGlobalVariable('argv')['ve']) {

0 commit comments

Comments
 (0)