-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.js
44 lines (37 loc) · 1.23 KB
/
extract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* To be able to use es6 modules */
require('babel-register')({
presets: [ 'env' ],
ignore: /node_modules\/(?!angular-translate-extract)/,
});
const { extract } = require('angular-translate-extract');
const fs = require('fs');
/* Generate translationKeys.xml for the Extractor from the JSON Wizard */
const wizardStates = JSON.parse(fs.readFileSync('src/app/wizard/wizard.json'));
const keys = [];
wizardStates.forEach(({contentKeys, subStates, stateName}) => {
if (contentKeys) {
contentKeys.forEach((key) => {
keys.push(`<key translate>${stateName}.${key}</key>`);
});
} else if (subStates && subStates.length > 0) {
const parent = stateName;
subStates.forEach(({contentKeys, stateName}) => {
contentKeys.map((key) => {
keys.push(`<key translate>${parent ? parent + '.' : ''}${stateName}.${key}</key>`);
});
});
}
})
fs.writeFileSync('src/assets/i18n/translationKeys.xml', keys.join('\n'));
/* Extract and create the JSONs */
new extract({
src: [
'src/assets/i18n/translationKeys.xml',
'src/app/**/*.js',
'src/app/**/*.html',
],
lang: ['en', 'es', 'cat'],
dest: 'src/assets/i18n',
safeMode: true, // Sometime clean translation
namespace: true
}, { basePath: '.' })