@@ -28,7 +28,6 @@ export const langTranslations = [
28
28
date : 'janvier' ,
29
29
} ,
30
30
translationReplacements : [
31
- [ / s o u r c e / g, 'target' ] ,
32
31
[ 'Hello' , 'Bonjour' ] ,
33
32
[ 'Updated' , 'Mis à jour' ] ,
34
33
[ 'just now' , 'juste maintenant' ] ,
@@ -46,7 +45,6 @@ export const langTranslations = [
46
45
date : 'Januar' ,
47
46
} ,
48
47
translationReplacements : [
49
- [ / s o u r c e / g, 'target' ] ,
50
48
[ 'Hello' , 'Hallo' ] ,
51
49
[ 'Updated' , 'Aktualisiert' ] ,
52
50
[ 'just now' , 'gerade jetzt' ] ,
@@ -66,7 +64,33 @@ export const externalServer = (outputPath: string) => {
66
64
return app . listen ( 4200 , 'localhost' ) ;
67
65
} ;
68
66
69
- export async function setupI18nConfig ( useLocalize = true ) {
67
+ export const formats = {
68
+ 'xlf' : {
69
+ ext : 'xlf' ,
70
+ sourceCheck : 'source-language="en-US"' ,
71
+ replacements : [
72
+ [ / s o u r c e / g, 'target' ] ,
73
+ ] ,
74
+ } ,
75
+ 'xlf2' : {
76
+ ext : 'xlf' ,
77
+ sourceCheck : 'srcLang="en-US"' ,
78
+ replacements : [
79
+ [ / s o u r c e / g, 'target' ] ,
80
+ ] ,
81
+ } ,
82
+ 'xmb' : {
83
+ ext : 'xmb' ,
84
+ sourceCheck : '<!DOCTYPE messagebundle' ,
85
+ replacements : [
86
+ [ / m e s s a g e b u n d l e / g, 'translationbundle' ] ,
87
+ [ / m s g / g, 'translation' ] ,
88
+ [ / < s o u r c e > .* ?< \/ s o u r c e > / g, '' ] ,
89
+ ] ,
90
+ } ,
91
+ } ;
92
+
93
+ export async function setupI18nConfig ( useLocalize = true , format : keyof typeof formats = 'xlf' ) {
70
94
// Add component with i18n content, both translations and localeData (plural, dates).
71
95
await writeFile ( 'src/app/app.component.ts' , `
72
96
import { Component, Inject, LOCALE_ID } from '@angular/core';
@@ -161,16 +185,16 @@ export async function setupI18nConfig(useLocalize = true) {
161
185
} else {
162
186
buildConfigs [ lang ] = {
163
187
outputPath,
164
- i18nFile : `src/locale/messages.${ lang } .xlf ` ,
165
- i18nFormat : `xlf` ,
188
+ i18nFile : `src/locale/messages.${ lang } .${ formats [ format ] . ext } ` ,
189
+ i18nFormat : format ,
166
190
i18nLocale : lang ,
167
191
} ;
168
192
}
169
193
} else {
170
194
if ( lang == sourceLocale ) {
171
195
i18n . sourceLocale = lang ;
172
196
} else {
173
- i18n . locales [ lang ] = `src/locale/messages.${ lang } .xlf ` ;
197
+ i18n . locales [ lang ] = `src/locale/messages.${ lang } .${ formats [ format ] . ext } ` ;
174
198
}
175
199
buildConfigs [ lang ] = { localize : [ lang ] } ;
176
200
}
@@ -184,17 +208,29 @@ export async function setupI18nConfig(useLocalize = true) {
184
208
} ) ;
185
209
186
210
// Extract the translation messages.
187
- await ng ( 'xi18n' , '--output-path=src/locale' ) ;
188
- await expectFileToExist ( 'src/locale/messages.xlf' ) ;
189
- await expectFileToMatch ( 'src/locale/messages.xlf' , `source-language="en-US"` ) ;
190
- await expectFileToMatch ( 'src/locale/messages.xlf' , `An introduction header for this sample` ) ;
211
+ await ng ( 'xi18n' , '--output-path=src/locale' , `--format=${ format } ` ) ;
212
+ const translationFile = `src/locale/messages.${ formats [ format ] . ext } ` ;
213
+ await expectFileToExist ( translationFile ) ;
214
+ await expectFileToMatch ( translationFile , formats [ format ] . sourceCheck ) ;
215
+ await expectFileToMatch ( translationFile , `An introduction header for this sample` ) ;
191
216
192
217
// Make translations for each language.
193
218
for ( const { lang, translationReplacements } of langTranslations ) {
194
219
if ( lang != sourceLocale ) {
195
- await copyFile ( 'src/locale/messages.xlf' , `src/locale/messages.${ lang } .xlf ` ) ;
220
+ await copyFile ( translationFile , `src/locale/messages.${ lang } .${ formats [ format ] . ext } ` ) ;
196
221
for ( const replacements of translationReplacements ) {
197
- await replaceInFile ( `src/locale/messages.${ lang } .xlf` , replacements [ 0 ] , replacements [ 1 ] as string ) ;
222
+ await replaceInFile (
223
+ `src/locale/messages.${ lang } .${ formats [ format ] . ext } ` ,
224
+ replacements [ 0 ] ,
225
+ replacements [ 1 ] as string ,
226
+ ) ;
227
+ }
228
+ for ( const replacement of formats [ format ] . replacements ) {
229
+ await replaceInFile (
230
+ `src/locale/messages.${ lang } .${ formats [ format ] . ext } ` ,
231
+ replacement [ 0 ] ,
232
+ replacement [ 1 ] as string ,
233
+ ) ;
198
234
}
199
235
}
200
236
}
0 commit comments