-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathi18next-scanner.config.js
96 lines (91 loc) · 2.22 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const fs = require('fs');
const chalk = require('chalk');
const typescriptTransform = require('i18next-scanner-typescript');
const languages = [
'en', // English (default)
'de', // German
'es', // Spanish
'fr', // French
'it', // Italian
'ja', // Japanese
'pl', // Polish
'ru', // Russian
'uk', // Ukrainian
'tr', // Turkish
'zh-TW', // Traditional Chinese
];
module.exports = {
input: [
'src/**/*.{ts,tsx}',
'!src/**/*.spec.{ts,tsx}',
'!src/**/*.stories.{ts,tsx}',
'!src/i18n/**',
'!**/node_modules/**',
],
output: './',
options: {
debug: true,
removeUnusedKeys: true,
func: {
list: ['i18n.t', 't'],
extensions: ['.js', '.jsx'],
},
trans: {
component: 'Trans',
i18nKey: 'i18nKey',
defaultsKey: 'defaults',
extensions: ['.js', '.jsx'],
fallbackKey: (ns, value) => value,
acorn: {
ecmaVersion: 10,
sourceType: 'module',
// Check out https://github.com/acornjs/acorn/tree/master/acorn#interface for additional options
},
},
lngs: languages,
ns: [
'translation',
],
defaultLng: languages[0],
defaultNs: 'translation',
defaultValue: (lng, ns, key) => {
return key;
// if (lng === languages[0]) {
// return key;
// }
// return '__STRING_NOT_TRANSLATED__';
},
resource: {
loadPath: 'static/locales/{{lng}}/{{ns}}.json',
savePath: 'static/locales/{{lng}}/{{ns}}.json',
jsonIndent: 2,
lineEnding: '\n',
},
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: '{{',
suffix: '}}',
},
transform: typescriptTransform({
extensions: ['.ts', '.tsx'],
}),
},
transform: function customTransform(file, enc, done) {
const { parser } = this;
const content = fs.readFileSync(file.path, enc);
let count = 0;
parser.parseFuncFromString(content, (key, options) => {
parser.set(key, {
...options,
nsSeparator: false,
keySeparator: false,
});
count += 1;
});
if (count > 0) {
console.log(`i18next-scanner: count=${chalk.cyan(count)}, file=${chalk.yellow(JSON.stringify(file.relative))}`);
}
done();
},
};