forked from jenseng/react-i18nliner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
32 lines (27 loc) · 1000 Bytes
/
main.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
var log = require('./util/createLogger')('preact-i18nline');
var preprocess = require("./preprocess");
var NewIndex = require("./newindex");
var createHasTranslatableText = require("./hasTranslatableText");
module.exports = function(i18nline) {
var proto = i18nline.processors.JsProcessor.prototype;
var hasTranslatableText = createHasTranslatableText(i18nline.config);
function preProcess(source) {
var fileData = proto.oldPreProcess.call(this, source);
// avoid a parse if we can
fileData.skip = fileData.skip && !hasTranslatableText(source);
if (!fileData.skip) {
var ast = fileData.ast || this.parse(source);
preprocess.ast(ast, i18nline.config);
fileData.ast = ast;
}
return fileData;
}
if (proto.preProcess !== preProcess) {
proto.oldPreProcess = proto.preProcess;
proto.preProcess = preProcess;
}
if (i18nline.Commands.Index !== NewIndex) {
i18nline.Commands.Index = NewIndex;
}
};
log.log('Initialized ' + log.name);