diff --git a/www/js/auth.js b/www/js/auth.js index b5d7ea6..b15ded9 100644 --- a/www/js/auth.js +++ b/www/js/auth.js @@ -36,7 +36,7 @@ function askLogout() { } function logout() { - $.getJSON(mkApiUrl('deletesession'), {}, function (data) { + $.getJSON(mkApiUrl('deletesession') + "?lang=" + USER_LANGUAGE, {}, function (data) { if (data.status === 'OK') { localStorage.setItem("username", ''); localStorage.setItem("password", ''); @@ -54,7 +54,8 @@ function logout() { var teamchoosercheckretried = false; function checkUserHasTeamOpenChooserIfNot(username) { $.getJSON(mkApiUrl('getstats'), { - user: username + user: username, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { if (data.stats.teamid && data.stats.teamid > 0) { @@ -118,7 +119,8 @@ function dosignup() { user: $('#usernameBox').val(), pass: $('#passwordBox').val(), name: $('#nameBox').val(), - email: $('#emailBox').val() + email: $('#emailBox').val(), + lang: USER_LANGUAGE }, function (data) { if (data === 'OK') { @@ -126,6 +128,7 @@ function dosignup() { $.post(mkApiUrl('login'), { user: $('#usernameBox').val(), pass: $('#passwordBox').val(), + lang: USER_LANGUAGE }, function (out) { if (out.status === 'OK') { loginOK(); @@ -175,7 +178,8 @@ function dologin() { $.post(mkApiUrl("login"), { user: $('#usernameBox').val(), - pass: $('#passwordBox').val() + pass: $('#passwordBox').val(), + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { diff --git a/www/js/location.js b/www/js/location.js index b003cec..b2b180d 100644 --- a/www/js/location.js +++ b/www/js/location.js @@ -139,7 +139,7 @@ function loadPlaces(lat, long) { if (!lockGot) { return; } - var url = mkApiUrl('places', 'gs') + "?lat=" + lat + "&long=" + long + "&radius=.5&names=1"; + var url = mkApiUrl('places', 'gs') + "?lat=" + lat + "&long=" + long + "&radius=.5&names=1&lang=" + USER_LANGUAGE; try { $.getJSON( url, @@ -196,7 +196,7 @@ var updatePosition = function (position) { function pingServer() { if (lockGot && gpsaccuracy < requiredaccuracy) { - $.getJSON(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude, function (data) { + $.getJSON(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude + "&lang=" + USER_LANGUAGE, function (data) { if (data.status == "ERROR" && logoutInProgress != true) { localStorage.setItem("no_autologin", "true"); username = null; diff --git a/www/js/main.js b/www/js/main.js index 99e9cfc..1b19b20 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -27,6 +27,8 @@ MUNZEE_CLIENT_ID = '616cecc70e17f4a3cb64146dce2d33f5'; MUNZEE_REDIRECT = 'http://gs.terranquest.net/munzee.php'; CODE_SCAN_COOLDOWN_SECONDS = 15; // Also change in CSS (.cooldown-fade-anim) +USER_LANGUAGE = "en-US"; + currentscreen = ""; /* * Runs when the app opens @@ -54,6 +56,16 @@ function onDeviceReady() { } } }); + setLocale(); +} + +function setLocale() { + navigator.globalization.getPreferredLanguage( + function (language) { + USER_LANGUAGE = language.value; + }, + function () {} + ); } // Depending on the device, a few examples are: diff --git a/www/js/shop.js b/www/js/shop.js index 8d25bcb..f271aa6 100644 --- a/www/js/shop.js +++ b/www/js/shop.js @@ -25,7 +25,8 @@ function buycoins(productId) { os: 'android', data: data.receipt, signature: data.signature, - id: productId + id: productId, + lang: USER_LANGUAGE }, function (result) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); @@ -53,7 +54,8 @@ function buycoins(productId) { os: 'ios', data: data.receipt, signature: data.signature, - id: productId + id: productId, + lang: USER_LANGUAGE }, function (result) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); @@ -81,7 +83,8 @@ function buyitem(id, cost) { $('#shopitem-' + id).prop('onclick', null).off('click'); $.getJSON(mkApiUrl('buyitem', 'gs'), { merchid: id, - cost: cost + cost: cost, + lang: USER_LANGUAGE }, function (data) { if (data.status == 'OK') { showSuccessMessage(data.message); @@ -142,7 +145,7 @@ function setcoinhtmlfromiap(coinsjson) { } function loadstorefront() { - $.getJSON(mkApiUrl('shopitems'), function (data) { + $.getJSON(mkApiUrl('shopitems') + "?lang=" + USER_LANGUAGE, function (data) { var content = ""; if (data.status == 'OK') { var items = data.items; @@ -163,7 +166,7 @@ function loadstorefront() { } function refreshcoins() { - $.getJSON(mkApiUrl('shopitems'), function (data) { + $.getJSON(mkApiUrl('shopitems') + "?lang=" + USER_LANGUAGE, function (data) { if (data.status == 'OK') { $('#coinbalance').text(data.balance); } diff --git a/www/js/user.js b/www/js/user.js index d951930..ddb14db 100644 --- a/www/js/user.js +++ b/www/js/user.js @@ -33,7 +33,8 @@ var terrainName = "Other"; */ function syncStats() { $.getJSON(mkApiUrl('getstats'), { - user: username + user: username, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { maxenergy = data.stats.maxenergy; @@ -57,7 +58,8 @@ function getChat() { $.getJSON(mkApiUrl('chat', 'cs'), { lat: latitude, long: longitude, - name: username + name: username, + lang: USER_LANGUAGE }, function (data) { data = sortResults(data, 'time', true); var content = ""; @@ -79,7 +81,7 @@ function getChat() { function privMsgSync() { $.getJSON( - mkApiUrl('privmsgs') + "?filter=unread", + mkApiUrl('privmsgs') + "?filter=unread&lang=" + USER_LANGUAGE, function (data) { if (data.status === 'OK') { if (data.msgs.length > 0) { @@ -98,7 +100,8 @@ skycons.add("weathericon", "clear-day"); function getWeather() { $.getJSON(mkApiUrl('getweather'), { lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { var currently = data.currently; rawWeatherData = currently; @@ -110,7 +113,8 @@ function getWeather() { function getTerrain() { $.getJSON(mkApiUrl('getterrain'), { lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { var terrainid = -1; var terrainstr = "Other"; @@ -159,7 +163,8 @@ $("#chatsendform").submit(function (event) { lat: latitude, long: longitude, msg: message, - name: username + name: username, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { $('#chatbox-input').val(""); diff --git a/www/screens/chooseteam.html b/www/screens/chooseteam.html index 5ff3381..0b5b1e5 100644 --- a/www/screens/chooseteam.html +++ b/www/screens/chooseteam.html @@ -50,7 +50,8 @@ //alert($('input[name=teamChooser]:checked').val()); var team = $('input[name=teamChooser]:checked').val(); $.getJSON(mkApiUrl('setteam', 'gs'), { - teamid: team + teamid: team, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { // We're all good. diff --git a/www/screens/home.html b/www/screens/home.html index 21f8518..3fabaf9 100644 --- a/www/screens/home.html +++ b/www/screens/home.html @@ -169,7 +169,8 @@ os: 'android', data: prod.receipt, signature: prod.signature, - id: prod.productId + id: prod.productId, + lang: USER_LANGUAGE }, function (result) { if (result.status == 'OK') { inAppPurchase.consume(prod.type, prod.receipt, prod.signature); diff --git a/www/screens/inventory.html b/www/screens/inventory.html index 877d295..dda8991 100644 --- a/www/screens/inventory.html +++ b/www/screens/inventory.html @@ -46,7 +46,8 @@ // Load the list of nearby players $.getJSON(mkApiUrl('nearby'), { lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { var content = ""; if (data.status === 'OK') { @@ -75,7 +76,8 @@ } $.getJSON(mkApiUrl('giveitem', 'gs'), { giveto: playername, - itemuuid: uuid + itemuuid: uuid, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { loadinventory(); @@ -92,7 +94,8 @@ function useitem(uuid) { $('#invitem-' + uuid).prop('onclick', null).off('click'); $.getJSON(mkApiUrl('useitem', 'gs'), { - itemuuid: uuid + itemuuid: uuid, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { loadinventory(); @@ -132,7 +135,8 @@ function loadinventory() { $.getJSON(mkApiUrl('inventory'), { - user: username + user: username, + lang: USER_LANGUAGE }, function (data) { var content = ""; if (data.status == 'OK') { diff --git a/www/screens/nearby.html b/www/screens/nearby.html index ea4bbcd..dcca17e 100644 --- a/www/screens/nearby.html +++ b/www/screens/nearby.html @@ -36,7 +36,8 @@ function loadnearby() { $.getJSON(mkApiUrl('nearby'), { lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { var content = ""; if (data.status === 'OK') { diff --git a/www/screens/place.html b/www/screens/place.html index 6ee3d7b..34cb0fd 100644 --- a/www/screens/place.html +++ b/www/screens/place.html @@ -87,7 +87,8 @@ function resync(firstload) { $('#place-refresh').addClass('fa-spin'); $.getJSON(mkApiUrl('getstats', 'gs'), { - user: username + user: username, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { maxenergy = data.stats.maxenergy; @@ -99,7 +100,8 @@ } }); $.getJSON(mkApiUrl('placestats', 'gs'), { - locationid: thisplace.properties.gameinfo.locationid + locationid: thisplace.properties.gameinfo.locationid, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { placeteam = data.stats.teamid; @@ -167,7 +169,8 @@ $.getJSON(mkApiUrl('attackplace', 'gs'), { locationid: thisplace.properties.gameinfo.locationid, lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { $('#capturebtn').text(data.message); @@ -205,7 +208,8 @@ $.getJSON(mkApiUrl('refillplace', 'gs'), { locationid: thisplace.properties.gameinfo.locationid, lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { $('#refillbtn').text(data.message); @@ -241,7 +245,8 @@ $.getJSON(mkApiUrl('claimplace', 'gs'), { locationid: thisplace.properties.gameinfo.locationid, lat: latitude, - long: longitude + long: longitude, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { $('#capturebtn').text(data.message); diff --git a/www/screens/profile.html b/www/screens/profile.html index 4022876..535a439 100644 --- a/www/screens/profile.html +++ b/www/screens/profile.html @@ -72,7 +72,8 @@ if (message !== '') { $.post(mkApiUrl('privmsgs'), { msg: message, - to: toplayer + to: toplayer, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK') { $('#privmsgbox').val(""); @@ -89,7 +90,8 @@ function loadPlayerStats(user) { $.getJSON(mkApiUrl('getstats'), { - user: user + user: user, + lang: USER_LANGUAGE }, function (data) { if (data.status === 'OK' && data.stats != null) { if (data.stats.level != null) { @@ -121,7 +123,7 @@ $('#loading-badges').html(' Loading...'); $('#loading-badges').css('display', 'block'); $.getJSON( - mkApiUrl('getbadges') + '?user=' + user, + mkApiUrl('getbadges') + '?user=' + user + "&lang=" + USER_LANGUAGE, function (data) { if (data.status === 'OK') { data.badges.forEach(function (item) { @@ -149,7 +151,7 @@ $('#privmsg-box').css('display', 'block'); $('#privmsgs').css('display', 'block'); $.getJSON( - mkApiUrl('privmsgs'), + mkApiUrl('privmsgs') + "?lang=" + USER_LANGUAGE, function (data) { if (data.status === 'OK') { $('#privmsgs').html("");