-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathi18next-scanner.config.js
54 lines (53 loc) · 1.43 KB
/
i18next-scanner.config.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
45
46
47
48
49
50
51
52
53
54
const i18nextConv = import('i18next-conv');
const Vinyl = require('vinyl');
module.exports = {
input: [
'src/index.html',
'src/app/**/*.ts',
],
options: {
func: {
list: ['i18nAttr'],
extensions: ['.ts'],
},
contextSeparator: '|',
pluralSeparator: '|',
ns: [
'categories',
'dietary-properties',
'explore',
'footer',
'meal-planner',
'navigation',
'search',
'shopping-list',
'starred-recipes',
],
resource: {
savePath: 'i18n/locales/templates/{{ns}}.pot',
},
},
flush: function() {
resources = this.parser.get();
Object.keys(resources).forEach(lng => {
const namespaces = resources[lng];
Object.keys(namespaces).forEach(ns => {
const object = namespaces[ns];
if (Object.keys(object).length == 0) return;
const path = this.parser.formatResourceSavePath(lng, ns);
const json = JSON.stringify(object, null, false);
const options = {
keyseparator: this.parser.options.keySeparator,
ctxSeparator: this.parser.options.contextSeparator,
ignorePlurals: !this.parser.options.plural,
}
i18nextConv.then(i18nextConv => i18nextConv.i18nextToPot(lng, json, options).then(buffer => {
this.push(new Vinyl({
path: path,
contents: Buffer.from(buffer.toString() + '\n')
}));
}));
});
});
}
};