forked from cncjs/cncjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-scanner.appconfig.js
56 lines (51 loc) · 1.69 KB
/
i18next-scanner.appconfig.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
55
56
/* eslint no-console: 0 */
/* eslint strict: 0 */
const fs = require('fs');
const chalk = require('chalk');
const languages = require('./build.config').languages;
module.exports = {
options: {
debug: false,
sort: false,
func: {
list: ['i18n.t', 't'],
extensions: ['.js', '.jsx']
},
lngs: languages,
defaultValue: '__L10N__', // to indicate that a default value has not been defined for the key
ns: [
'resource' // default
],
defaultNs: 'resource',
resource: {
loadPath: 'src/app/i18n/{{lng}}/{{ns}}.json',
savePath: 'src/app/i18n/{{lng}}/{{ns}}.json', // or 'src/app/i18n/${lng}/${ns}.saveAll.json'
jsonIndent: 4
},
nsSeparator: ':', // namespace separator
keySeparator: '.', // key separator
pluralSeparator: '_', // plural separator
contextSeparator: '_', // context separator
interpolation: {
prefix: '{{',
suffix: '}}'
}
},
transform: function(file, enc, done) {
'use strict';
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
let count = 0;
parser.parseFuncFromString(content, { list: ['i18n._', 'i18n.__'] }, (key, options) => {
parser.set(key, Object.assign({}, options, {
nsSeparator: false,
keySeparator: false
}));
++count;
});
if (count > 0) {
console.log(`[i18next-scanner] transform: count=${chalk.cyan(count)}, file=${chalk.yellow(JSON.stringify(file.relative))}`);
}
done();
}
};