-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathi18nliner.js
100 lines (87 loc) · 2.28 KB
/
i18nliner.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var fs;
var maybeLoadJSON = function (path){
fs = fs || require("fs");
var data = {}
if (fs.existsSync(path)) {
try {
data = JSON.parse(fs.readFileSync(path).toString());
} catch (e) {
console.log(e);
}
}
return data;
}
var I18nliner = {
ignore () {
fs = fs || require("fs");
var ignores = [];
if (fs.existsSync(".i18nignore")) {
ignores = fs.readFileSync(".i18nignore").toString().trim().split(/\r?\n|\r/);
}
return ignores;
},
set (key, value, fn) {
var prevValue = this.config[key];
this.config[key] = value;
if (fn) {
try {
fn();
}
finally {
this.config[key] = prevValue;
}
}
},
loadConfig () {
var config = maybeLoadJSON(".i18nrc");
for (var key in config) {
if (key !== "plugins") {
this.set(key, config[key]);
}
}
// plugins need to be loaded last to allow them to get
// the full config option when they are initialized
if (config.plugins && config.plugins.length > 0) {
this.loadPlugins(config.plugins);
}
},
loadPlugins (plugins) {
plugins.forEach(function(pluginName) {
var plugin = require(pluginName);
if (plugin.default) plugin = plugin.default;
plugin({
processors: this.Commands.Check.processors,
config: this.config
});
}.bind(this));
},
config: {
inferredKeyFormat: 'underscored_crc32',
/*
literal:
Just use the literal string as its translation key
underscored:
Underscored ascii representation of the string, truncated to
<underscoredKeyLength> bytes
underscored_crc32:
Underscored, with a checksum at the end to avoid collisions
*/
underscoredKeyLength: 50,
basePath: ".",
/*
Where to look for files. Additionally, the output json file
will be relative to this.
*/
directories: [],
/*
Further limit extraction to these directories. If empty,
I18nliner will look everywhere under <basePath>
*/
babylonPlugins: ["jsx", "classProperties", "objectRestSpread"]
/*
The set of babylon plugins to use in AST parsing.
See: https://github.com/babel/babel/tree/master/packages/babylon#plugins
*/
}
};
export default I18nliner;