diff options
Diffstat (limited to 'lang/loader.js')
-rw-r--r-- | lang/loader.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lang/loader.js b/lang/loader.js new file mode 100644 index 0000000..fdd5ec2 --- /dev/null +++ b/lang/loader.js @@ -0,0 +1,46 @@ +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 { + 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()); + } +} |