@@ -14,9 +14,26 @@ export default async function () {
14
14
15
15
// Set configurations for each locale.
16
16
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
+ } ,
20
37
] ;
21
38
22
39
await updateJsonFile ( 'angular.json' , workspaceJson => {
@@ -61,7 +78,12 @@ export default async function () {
61
78
describe('workspace-project App', () => {
62
79
it('should display welcome message', () => {
63
80
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 } ');
65
87
});
66
88
67
89
afterEach(async () => {
@@ -75,29 +97,38 @@ export default async function () {
75
97
` ) ;
76
98
}
77
99
78
- // Add a translatable element .
100
+ // Add translatable elements .
79
101
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' ) ;
81
105
82
106
// Extract the translation messages and copy them for each language.
83
107
await ng ( 'xi18n' , '--output-path=src/locale' ) ;
84
108
await expectFileToExist ( 'src/locale/messages.xlf' ) ;
85
109
await expectFileToMatch ( 'src/locale/messages.xlf' , `source-language="en-US"` ) ;
86
110
await expectFileToMatch ( 'src/locale/messages.xlf' , `An introduction header for this sample` ) ;
87
111
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 ) {
89
116
if ( lang != 'en' ) {
90
117
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 } ` ) ;
93
124
}
94
125
}
95
126
96
127
for ( const { lang, translation, outputPath } of langTranslations ) {
97
128
// Build each locale and verify the output.
98
129
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 ) ;
101
132
102
133
// E2E to verify the output runs and is correct.
103
134
if ( getGlobalVariable ( 'argv' ) [ 've' ] ) {
0 commit comments