forked from jenseng/react-i18nliner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hasTranslatableText.js
26 lines (20 loc) · 917 Bytes
/
hasTranslatableText.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
var log = require('./util/createLogger')('preact-i18nline:hasTranslatableText');
var escapeRegExp = require("./util/escapeRegExp");
var getTranslatePattern = function(config) {
var pattern = 'translate=["\']yes["\']';
var parts = config.autoTranslateTags || [];
if (parts.length)
pattern += "|<" + parts.map(escapeRegExp).join("|<");
return new RegExp(pattern);
};
module.exports = function(config) {
var pattern;
config = config || {};
config.autoTranslateTags = typeof config.autoTranslateTags === 'string' ? config.autoTranslateTags.split(',') : config.autoTranslateTags || [];
config.neverTranslateTags = typeof config.neverTranslateTags === 'string' ? config.neverTranslateTags.split(',') : config.neverTranslateTags || [];
return function(source) {
pattern = pattern || getTranslatePattern(config);
return !!source.match(pattern);
};
};
log.log('Initialized ' + log.name);