forked from antfu-collective/vitesse-webext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-scanner.config.js
67 lines (62 loc) · 2.03 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 path = require('path');
const fs = require('fs');
const typescript = require('typescript');
module.exports = {
input: ['src/**/*.{ts,tsx}', '!src/**/*.spec.{ts,tsx}', '!src/locales/**', '!**/node_modules/**', 'src/**/*.d.ts'],
output: './',
options: {
func: {
list: ['browser.i18n.getMessage', '', 't'],
extensions: ['.js', '.jsx']
},
trans: {
component: 'Trans',
i18nKey: 'i18nKey',
defaultsKey: 'defaults',
extensions: ['.js', '.jsx'],
fallbackKey: function (ns, value) {
return value;
},
acorn: {
ecmaVersion: 2020,
sourceType: 'module' // defaults to 'module'
}
},
lngs: ['en'],
ns: ['messages'],
defaultLng: 'en',
defaultNs: 'messages',
defaultValue: '__STRING_NOT_TRANSLATED__',
resource: {
loadPath: 'src/locales/{{lng}}/messages.json',
savePath: 'src/locales/{{lng}}/messages.json',
jsonIndent: 4,
lineEnding: '\n'
},
nsSeparator: ':', // namespace separator
keySeparator: '.', // key separator
interpolation: {
prefix: '{{',
suffix: '}}'
}
},
transform: function typescriptTransform(file, enc, done) {
const options = {
tsOptions: {
target: 'es2020'
},
extensions: ['.ts', '.tsx']
};
const { base, ext } = path.parse(file.path);
if (options.extensions.includes(ext) && !base.includes('.d.ts')) {
const content = fs.readFileSync(file.path, enc);
const { outputText } = typescript.transpileModule(content, {
compilerOptions: options.tsOptions,
fileName: path.basename(file.path)
});
this.parser.parseTransFromString(outputText);
this.parser.parseFuncFromString(outputText);
}
done();
}
};