forked from CrestoneDigital/CartoDB-Translation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n-cdb-translate.js
54 lines (47 loc) · 1.84 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
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._($(el).text().trim());
if (tmp != $(el).text().trim() && $(el).children().length == 0) {
$(el).text(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._($(el).text().trim());
if (tmp != $(el).text().trim() && $(el).children().length == 0) {
$(el).text(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
};
})();