-
Notifications
You must be signed in to change notification settings - Fork 11
/
assets_js_bitrequest_lang_controller.js
112 lines (105 loc) · 3.16 KB
/
assets_js_bitrequest_lang_controller.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// To add tour own translation copy the file assets_js_bitrequest_lang_en.js and replace the filename with your countrycode suffix.
// Read further instruction in your copied file
$(document).ready(function() {
init_tl();
//lang_dat
//setlangcode
//systemlang
//translate
//transclear
});
function init_tl() {
// Globals
cancelbttn = translate("cancelbttn");
okbttn = translate("okbttn");
$(".tl_page1").text(translate("currencies"));
$(".tl_page2").text(translate("requests"));
$(".tl_page3").text(translate("settings"));
$(".tl_page4").text(translate("payoff"));
$(".tl_page5").attr("placeholder", translate("accountsettings"));
$(".tl_page6").text(translate("iwouldliketogetpaid"));
$(".tl_page6").text(translate("iwouldliketogetpaid"));
$("#canceldialog").text(cancelbttn);
$("#execute").text(okbttn);
$("#add_erc20 .icon-plus").text(translate("more"));
$("#scanner_toolbar > p").text(translate("encodeyoraddress"));
}
function lang_dat(lang) {
const lower = lang.toLowerCase(),
single = lower.split("-")[0];
return {
"lower": lower,
"single": single
};
}
function setlangcode() {
const settingcache = br_get_local("settings", true);
if (settingcache) { // get saved language
const lang_settings = settingcache[2];
if (lang_settings) {
const setlang = lang_settings.selected,
sl_length = setlang.length;
if (sl_length && sl_length < 7) {
const translation = translate("obj");
if (translation[setlang]) {
return setlang;
}
}
}
}
// get system language
return systemlang();
}
function systemlang() { // get system language
const lang = lang_dat(glob_language),
lang_lower = lang.lower,
lang_single = lang.single,
translation = translate("obj"),
tl_long = translation[lang_lower],
tl_short = translation[lang_single];
return (tl_long) ? lang_lower :
(tl_short) ? lang_single : "en";
}
function translate(id, dat) {
const data = (dat) ? dat : {},
languages = {
"en": {
"lang": "English",
"flag": "🇺🇲",
"obj": lang_en(id, data)
},
"nl": {
"lang": "Dutch",
"flag": "🇾🇪",
"obj": lang_nl(id, data)
},
"fr": {
"lang": "French",
"flag": "🇨🇵",
"obj": lang_fr(id, data)
}
}
if (id == "obj") {
return languages;
}
try {
const lang_string = languages[glob_langcode].obj;
if (lang_string) {
return lang_string;
}
// use english if string is not found.
return languages.en.obj;
} catch (err) {
console.log(err);
// use english if language is not found.
return languages.en.obj;
}
}
// translate and clear accents
function transclear(id, dat) {
const tl = translate(id, dat);
if (tl) {
return clear_accents(tl);
}
return tl;
}