-
Notifications
You must be signed in to change notification settings - Fork 4
/
i18next-scanner.config.js
52 lines (48 loc) · 1.16 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
const fs = require("fs");
const path = require("path");
let hearthstoneKeys = [];
const hearthstoneDir = path.resolve(__dirname, "hearthstone", "en");
const filenames = fs.readdirSync(hearthstoneDir);
for (const filename of filenames) {
const file = fs.readFileSync(path.resolve(hearthstoneDir, filename));
const contents = JSON.parse(file);
hearthstoneKeys = hearthstoneKeys.concat(Object.keys(contents));
}
module.exports = {
options: {
// use strings as keys
nsSeparator: false,
keySeparator: false,
// settings
defaultNs: "frontend",
lngs: ["en"],
resource: {
loadPath: "{{lng}}/{{ns}}.json",
savePath: "{{lng}}/{{ns}}.json",
},
func: false,
trans: {
component: "Trans",
fallbackKey: true,
},
defaultValue: (language, namespace, key) => key,
},
transform(file, enc, done) {
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
const ext = path.extname(file.path);
parser.parseFuncFromString(
content,
{
list: ["t"],
},
(key, options) => {
if (hearthstoneKeys.indexOf(key) !== -1 || key.startsWith("GLOBAL_")) {
return;
}
parser.set(key, options);
},
);
done();
},
};