-
Notifications
You must be signed in to change notification settings - Fork 73
/
i18n.config.js
66 lines (61 loc) · 1.91 KB
/
i18n.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
const fs = require('fs');
const chalk = require('chalk');
module.exports = {
input: [
'./src/**/*.ts',
'./react/src/**/*.tsx',
// Use ! to filter out files or directories
],
output: './',
options: {
debug: true,
removeUnusedKeys: false,
func: {
list: ['_t', '_tr', '_text', 't'], // _t for normal text, _tr for HTML text, t for react
extensions: ['.ts', '.js', '.jsx', '.tsx']
},
trans: false,
lngs: ['en', 'ko', 'de', 'el', 'es', 'fi', 'fr', 'id', 'it', 'ja', 'mn', 'ms', 'pl', 'pt', 'pt-BR', 'ru', 'tr', 'vi', 'zh-CN', 'zh-TW'], // supported languages
defaultLng: 'en',
defaultNs: 'resource',
defaultValue: function(lng, ns, key) {
if (lng === 'en') {
// Return key as the default value for English language
return key;
}
// Return the string '__NOT_TRANSLATED__' for other languages
return '__NOT_TRANSLATED__';
},
resource: {
loadPath: 'resources/i18n/{{lng}}.json',
savePath: 'resources/i18n/{{lng}}.json',
jsonIndent: 2,
lineEnding: '\n'
},
nsSeparator: ':', // '.',//false, // namespace separator
keySeparator: '.', // false, // key separator
interpolation: {
prefix: '{{',
suffix: '}}'
},
plural: false
},
transform: function customTransform(file, enc, done) {
'use strict';
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
let count = 0;
parser.parseFuncFromString(content, {list: ['_t', '_tr', '_text', 't']}, (key, options) => {
parser.set(key, Object.assign({}, options, {
nsSeparator: false,
keySeparator: '.'
}));
++count;
});
let colored = file.path.includes('/react/src') ? chalk.magenta : chalk.yellow;
if (count > 0) {
console.log(`i18next-scanner: count=${chalk.cyan(count)}, file=${colored(JSON.stringify(file.relative))}`);
}
done();
}
};