forked from cosmostation/cosmostation-chrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-scanner.config.js
67 lines (63 loc) · 1.74 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
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
module.exports = {
input: [
'src/Popup/**/*.{ts,tsx}',
// Use ! to filter out files or directories
'!src/Popup/**/*.spec.{ts,tsx}',
'!src/Popup/i18n/**',
'!**/node_modules/**',
],
output: './',
options: {
debug: true,
sort: true,
func: {
list: ['t'],
extensions: ['.ts', '.tsx'],
},
trans: {
component: 'Trans',
i18nKey: 'i18nKey',
defaultsKey: 'defaults',
extensions: ['.ts', '.tsx'],
fallbackKey(ns, value) {
return value;
},
acorn: {
ecmaVersion: 10, // defaults to 10
sourceType: 'module', // defaults to 'module'
// Check out https://github.com/acornjs/acorn/tree/master/acorn#interface for additional options
},
},
lngs: ['en', 'ko'],
ns: ['translation'],
defaultLng: 'en',
defaultNs: 'translation',
defaultValue: '__STRING_NOT_TRANSLATED__',
resource: {
loadPath: 'src/Popup/i18n/{{lng}}/{{ns}}.json',
savePath: 'src/Popup/i18n/{{lng}}/{{ns}}.json',
jsonIndent: 2,
lineEnding: '\n',
},
nsSeparator: ':', // namespace separator
keySeparator: '.', // key separator
interpolation: {
prefix: '{{',
suffix: '}}',
},
},
transform: function customTransform(file, enc, done) {
const { parser } = this;
const content = fs.readFileSync(file.path, enc);
let count = 0;
parser.parseFuncFromString(content, { list: ['i18next._', 'i18next.__'] }, (key, options) => {
parser.set(key, { ...options, nsSeparator: false, keySeparator: false });
count += 1;
});
if (count > 0) {
console.log(`i18next-scanner: count=${count}, file=${JSON.stringify(file.relative)}`);
}
done();
},
};