forked from DestinyItemManager/DIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-scanner.config.js
77 lines (69 loc) · 2.24 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
const fs = require('fs');
module.exports = {
input: ['src/app/**/*.{js,jsx,ts,tsx}', 'src/browsercheck.js'],
output: './',
options: {
debug: false,
removeUnusedKeys: true,
sort: true,
func: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
lngs: ['en'],
ns: ['translation'],
defaultLng: 'en',
resource: {
loadPath: 'config/i18n.json',
savePath: 'src/locale/en.json',
jsonIndent: 2,
lineEnding: '\n',
},
context: true,
contextFallback: true,
contextDefaultValues: ['male', 'female'],
allowDynamicKeys: true,
},
transform: function customTransform(file, enc, done) {
'use strict';
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
// prettier-ignore
const contexts = {
compact: ['compact'],
max: ['Max'],
};
// prettier-ignore
const keys = {
buckets: { list: ['General', 'Inventory', 'Postmaster', 'Progress', 'Unknown'] },
cooldowns: { list: ['Grenade', 'Melee', 'Super'] },
difficulty: { list: ['Normal', 'Hard'] },
minMax: { list: ['Min', 'Max'] },
progress: { list: ['Bounties', 'Items', 'Quests'] },
sockets: { list: ['Mod', 'Ability', 'Shader', 'Ornament', 'Fragment', 'Aspect', 'Projection', 'Transmat', 'Super'] },
unsupported: { list: ['Unsupported', 'Steam'] },
};
parser.parseFuncFromString(content, { list: ['t', 'tl', 'DimError'] }, (key, options) => {
if (options.metadata?.context) {
// Add context based on metadata
delete options.context;
const context = contexts[options.metadata?.context];
parser.set(key, options);
for (let i = 0; i < context?.length; i++) {
parser.set(`${key}${parser.options.contextSeparator}${context[i]}`, options);
}
}
if (options.metadata?.keys) {
// Add keys based on metadata (dynamic or otherwise)
const list = keys[options.metadata?.keys].list;
for (let i = 0; i < list?.length; i++) {
parser.set(`${key}${list[i]}`, options);
}
}
// Add all other non-metadata related keys w/ default options
if (!options.metadata) {
parser.set(key, options);
}
});
done();
},
};