forked from CrestoneDigital/CartoDB-Translation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n-cdb-translate.js
71 lines (63 loc) · 2.93 KB
/
i18n-cdb-translate.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
i18nTranslate = (function () {
var instance;
function _translate(parentEl) {
if (parentEl) {
$(parentEl).find('div, a, li, label, input, span, h5, h4, h3, h2, h1, p, button, strong, small').each(function (idx, el) {
var tmp = $.i18n.dict[$(el).text().toLowerCase().trim()] ? $.i18n._($(el).text().toLowerCase().trim()) : $(el).text().trim();
if (tmp != $(el).text().trim() && $(el).children().length == 0) {
$(el).text(tmp);
} else {
var tmpTxtAr = $(el).contents().filter(function(){
return this.nodeType == 3;
}), i
for (i=0; i< tmpTxtAr.length; i++) {
tmp = $.i18n.dict[tmpTxtAr[i].nodeValue.trim().toLowerCase()] ? $.i18n._(tmpTxtAr[i].nodeValue.trim().toLowerCase()) : tmpTxtAr[i].nodeValue;
tmpTxtAr[i].nodeValue = tmp;
}
}
});
$('* [placeholder]').each(function (idx, el) {
var tmp = $.i18n._($(el).prop('placeholder'))
if (tmp != $(el).prop('placeholder')) {
$(el).prop('placeholder', tmp);
}
});
$('* [title]').each(function (idx, el) {
var tmp = $.i18n._($(el).prop('title'));
if (tmp != $(el).prop('title')) {
$(el).prop('title', tmp);
}
});
} else {
$('div, a, li, label, input, span, h5, h4, h3, h2, h1, p, button, strong, small').each(function (idx, el) {
var tmp = $.i18n.dict[$(el).text().toLowerCase().trim()] ? $.i18n._($(el).text().toLowerCase().trim()) : $(el).text().trim();
if (tmp != $(el).text().trim() && $(el).children().length == 0) {
$(el).text(tmp);
} else {
var tmpTxtAr = $(el).contents().filter(function(){
return this.nodeType == 3;
}), i
for (i=0; i< tmpTxtAr.length; i++) {
tmp = $.i18n.dict[tmpTxtAr[i].nodeValue.trim().toLowerCase()] ? $.i18n._(tmpTxtAr[i].nodeValue.trim().toLowerCase()) : tmpTxtAr[i].nodeValue;
tmpTxtAr[i].nodeValue = tmp;
}
}
});
$('* [placeholder]').each(function (idx, el) {
var tmp = $.i18n._($(el).prop('placeholder'));
if (tmp != $(el).prop('placeholder')) {
$(el).prop('placeholder', tmp);
}
})
$('* [title]').each(function (idx, el) {
var tmp = $.i18n._($(el).prop('title'))
if (tmp != $(el).prop('title')) {
$(el).prop('title', tmp);
}
})
}
}
return {
translate: _translate
}
})();