aboutsummaryrefslogtreecommitdiff
path: root/lang/loader.js
blob: 205d8982f3eed354d35c42fc89a2574d6339c902 (plain)
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
function getCookie(cname) {
   var name = cname + "=";
   var decodedCookie = decodeURIComponent(document.cookie);
   var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
    return "";
}

if (getCookie("kartik_lang").trim() === "") {
    document.cookie = "kartik_lang=en; path=/";
}

if (typeof native === "boolean" && !native) {
    try {
        global.lp   = getCookie("kartik_lang");
        global.ll_length = getCookie("kartik_i18n_" + lp) - 1 + 2;
        global.ll_raw = "";
        
        for (i = 1; i <= ll_length; i++) {
            global.ll_raw = ll_raw + getCookie("kartik_i18n_" + lp + "_" + (i - 1));
        }
        
        global.lang = JSON.parse(ll_raw);
    } catch (e) {
        console.error(e);
        global.lp   = "en";
        global.lang = JSON.parse(window.fetch("./lang/" + lp + ".json").toString());
    }    
} else {
    if (typeof webview !== "undefined") {
        console.log("Delaying language files loading");
        if (location.hash === "#ready") {
            try {
                global.lp   = require('electron').remote.getCurrentWindow().lp.trim();
                global.lang = JSON.parse(require('fs').readFileSync("./lang/" + lp + ".json").toString());
            } catch (e) {
                console.error(e);
                global.lp   = "en";
                global.lang = JSON.parse(require('fs').readFileSync("./lang/" + lp + ".json").toString());
            }
        }
    } else {
        try {
            global.lp   = require('electron').remote.getCurrentWindow().lp.trim();
            global.lang = JSON.parse(require('fs').readFileSync("./lang/" + lp + ".json").toString());
        } catch (e) {
            console.error(e);
            global.lp   = "en";
            global.lang = JSON.parse(require('fs').readFileSync("./lang/" + lp + ".json").toString());
        }
    }
}