From 10c4cd6bf463656bab3d2b3f15d0db9c95605d5e Mon Sep 17 00:00:00 2001 From: XProger Date: Thu, 21 Feb 2019 06:11:01 +0300 Subject: [PATCH] fix automatic language detector for Web version --- src/platform/web/index.php | 94 +++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/src/platform/web/index.php b/src/platform/web/index.php index a225fc5..0674437 100644 --- a/src/platform/web/index.php +++ b/src/platform/web/index.php @@ -111,30 +111,32 @@ } proc.connect(audioContext.destination); } - - function getLanguage() { - var lang = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage; - var id = 0; - if (lang == "fr") { - id = 1; - } else if (lang == "de") { - id = 2; - } else if (lang == "es") { - id = 3; - } else if (lang == "it") { - id = 4; - } else if (lang == "pl") { - id = 5; - } else if (lang == "pt") { - id = 6; - } else if (lang == "ru" || lang == "be" || lang == "uk") { - id = 7; - } else if (lang == "ja") { - id = 8; - } - Module.ccall('set_def_lang', 'null', ['number'], [id]); - } - + + function getLanguage() { + var lang = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage; + if (!lang) return; + var id = 0; + lang = lang.substring(0, 2); + if (lang == "fr") { + id = 1; + } else if (lang == "de") { + id = 2; + } else if (lang == "es") { + id = 3; + } else if (lang == "it") { + id = 4; + } else if (lang == "pl") { + id = 5; + } else if (lang == "pt") { + id = 6; + } else if (lang == "ru" || lang == "be" || lang == "uk") { + id = 7; + } else if (lang == "ja") { + id = 8; + } + Module.ccall('set_def_lang', 'null', ['number'], [id]); + } + // unlock audio context after user interaction var userAction = function() { if (audioContext && audioContext.state == "suspended") { @@ -142,7 +144,7 @@ window.removeEventListener('touchstart', userAction, false); window.removeEventListener('click', userAction, false); console.log("resume playback"); - }); + }); } }; window.addEventListener('touchstart', userAction, false); @@ -248,9 +250,9 @@ }; reader.readAsArrayBuffer(event.target.files[0]); } - /* - var db; - var request = indexedDB.open("db"); + /* + var db; + var request = indexedDB.open("db"); request.onupgradeneeded = function() { console.log("!!!!!!!! NO DB!"); }; @@ -262,32 +264,32 @@ request.onsuccess = function() { function logTimestamps(timestamps) { console.log('There are ' + timestamps.length + - ' timestamp(s) saved in IndexedDB: ' + timestamps.join(', ')); + ' timestamp(s) saved in IndexedDB: ' + timestamps.join(', ')); } - - function backupSaves() { + + function backupSaves() { var transaction = db.transaction("FILE_DATA", 'readonly'); var store = transaction.objectStore("FILE_DATA"); store.get("level/1/GYMLOAD.PNG").onsuccess = function(e) { - var value = e.target.result; - // value will be: { zip: {}, foo: { bar: { baz: 1 } } } - console.log(value); - var data = value; - var a = document.createElement("a"); - - a.href = URL.createObjectURL(new Blob([data])); - a.download = "savegame.dat"; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); + var value = e.target.result; + // value will be: { zip: {}, foo: { bar: { baz: 1 } } } + console.log(value); + var data = value; + var a = document.createElement("a"); + + a.href = URL.createObjectURL(new Blob([data])); + a.download = "savegame.dat"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); }; - } + } */ - function restoreSaves() { - alert('restore'); - } + function restoreSaves() { + alert('restore'); + }