forked from jamaljsr/polar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.i18next-scanner.js
52 lines (48 loc) · 1.35 KB
/
.i18next-scanner.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
const typescript = require('typescript');
const fs = require('fs');
const path = require('path');
module.exports = {
input: [
'src/**/*.{ts,tsx}',
// Use ! to filter out files or directories
'!src/**/*.spec.{ts,tsx}',
],
output: './',
options: {
debug: true,
func: {
list: ['i18next.t', 'i18n.t', 't'],
},
trans: {
defaultsKey: 'defaults',
},
lngs: ['en-US', 'es'],
defaultLng: 'en-US',
ns: ['translation'],
defaultNs: 'translation',
defaultValue: '__MISSING__TRANSLATION__',
resource: {
loadPath: 'src/i18n/locales/{{lng}}.json',
savePath: 'src/i18n/locales/{{lng}}.json',
},
nsSeparator: ':',
keySeparator: false,
},
transform: function transform(file, enc, done) {
const { base, ext } = path.parse(file.path);
// custom transform for typescript files
if (['.ts', '.tsx'].includes(ext) && !base.includes('.d.ts')) {
const content = fs.readFileSync(file.path, enc);
// convert ts code into es2018 code that the parser can injest
const { outputText } = typescript.transpileModule(content, {
compilerOptions: {
target: 'es2018',
},
fileName: path.basename(file.path),
});
this.parser.parseTransFromString(outputText);
this.parser.parseFuncFromString(outputText);
}
done();
},
};