-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathi18next-scanner.config.js
73 lines (72 loc) · 1.83 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
var fs = require("fs");
module.exports = {
input: ["build/tmp/**/*.{js,jsx}"],
options: {
debug: true,
removeUnusedKeys: true,
func: {
list: ["t", "i18n.t"],
extensions: [".js", ".jsx"],
},
trans: {
component: "Trans",
i18nKey: "i18nKey",
extensions: [".js", ".jsx"],
acorn: {
ecmaVersion: 2020,
sourceType: "module", // defaults to 'module'
// Check out https://github.com/acornjs/acorn/tree/master/acorn#interface for additional options
},
},
lngs: [
"en",
// "ja",
// "zh",
// "ko",
// "es",
// "ms",
// "id",
// "ru",
// "it",
// "hu",
// "tr",
// "vi",
// "de",
],
ns: ["translation"],
defaultLng: "en",
defaultNs: "translation",
resource: {
loadPath: "./public/locales/{{lng}}/{{ns}}.json",
savePath: "./public/locales/{{lng}}/{{ns}}.json",
jsonIndent: 2,
// lineEnding: "\n",
},
nsSeparator: false, // namespace separator
keySeparator: false, // key separator
interpolation: {
prefix: "{{",
suffix: "}}",
},
},
transform: function customTransform(file, enc, done) {
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
const dateDefaults = {
"NO_TL.absoluteDate": "{{date, absolute}}",
"NO_TL.longDate": "{{date, long}}",
"NO_TL.relativeDate": "{{date, ago}}",
"NO_TL.shortDate": "{{date, short}}",
"NO_TL.shortDateTime": "{{date, datetime}}",
};
parser.parseFuncFromString(content, function (key, options) {
if (dateDefaults[key]) {
options.defaultValue = dateDefaults[key];
} else {
options.defaultValue = key; // use key as the value
}
parser.set(key, options);
});
done();
},
};