-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-localization-tags.js
35 lines (28 loc) · 1.2 KB
/
parse-localization-tags.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
var parseLocalizationTags = (function () {
'use strict';
/**
* parseLocalizationTags removes brackets and translator notes from html so that
* compilation of translated html files is not required during the development
* process
*
* translation tags are of the format: [[ english version | translator notes ]]
* this filter will cause these tags to be rendered as: english version
*/
var parseLocalizationTags = function(data) {
if (data && typeof data === 'string') {
data = data.replace(/(?:'"|"')(?:\[\[)([^\|]*)(?:\|[^\]]*]])(?:'"|"')/g, handleDoubleWrappedTags);
data = data.replace(/(?:\[\[)([^\|]*)(?:\|[^\]]*]])/g, handleRegularTags);
}
return data;
};
var handleDoubleWrappedTags = function(wholeTag, contents) {
return '"\'' + contents.replace(/(?:\[\[)([^\]]*)(?:]])/g, '\' + $1 + \'') + '\'"';
};
var handleRegularTags = function(wholeTag, contents) {
return contents.replace(/(?:\[\[)([^\]]*)(?:]])/g, '{{$1}}');
};
$(document).ready(function () {
document.body.innerHTML = parseLocalizationTags(document.body.innerHTML);
});
return parseLocalizationTags;
})();