From a3eed0d7588e596520b00cc0066ac964f83464b6 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Wed, 12 Apr 2017 22:42:23 +0200 Subject: [PATCH] Extract strings to lang files --- js/admin.js | 18 +++++++++--------- js/main.js | 4 ++-- js/pass.js | 8 ++++---- lang/en.php | 9 +++++++++ lang/pl.php | 9 +++++++++ utils/handleuser.php | 8 ++++---- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/js/admin.js b/js/admin.js index faaec1d..0153ec0 100644 --- a/js/admin.js +++ b/js/admin.js @@ -30,11 +30,11 @@ function editUser() { var userForm = document.getElementsByName('user')[0]; var userLogin = userForm.options[userForm.selectedIndex].text; if (userLogin == auth) { - alert('Your can\'t edit your own user with this tool'); + alert(lang['selfeditwarn']); return; } - var message = '
You are editing user ' + userLogin + '
'; - message += '
Delete user
'; + var message = '
' + sprintf(lang['editinguser'], '' + userLogin + '') + '
'; + message += '
' + lang['deluser'] + '
'; message += '
'; var form = '
'; @@ -47,14 +47,14 @@ function editUser() { } function confirmedDelete(login) { - return confirm('Warning!\n\nYou are going to permanently delete user "' + login + '", together with all their routes and positions.\n\nAre you sure?'); + return confirm(sprintf(lang['deletewarn'], '"' + login + '"')); } function submitUser(action) { var form = document.getElementById('userForm'); var login = form.elements['login'].value; if (!login) { - alert("All fields are required"); + alert(lang['allrequired']); return; } var pass = null; @@ -63,11 +63,11 @@ function submitUser(action) { pass = form.elements['pass'].value; pass2 = form.elements['pass2'].value; if (!pass || !pass2) { - alert("All fields are required"); + alert(lang['allrequired']); return; } if (pass != pass2) { - alert("Passwords don't match"); + alert(lang['passnotmatch']); return; } } else { @@ -84,7 +84,7 @@ function submitUser(action) { var root = xml.getElementsByTagName('root'); if (root.length && getNode(root[0], 'error') == 0) { removeModal(); - alert("Action completed successfully"); + alert(lang['actionsuccess']); if (action == 'delete') { // select current user in users form var f = document.getElementsByName('user')[0]; @@ -96,7 +96,7 @@ function submitUser(action) { errorMsg = getNode(root[0], 'message'); if (errorMsg) { message = errorMsg; } } - alert("Something went wrong\n" + message); + alert(lang['actionfailure'] + '\n' + message); xhr = null; } } diff --git a/js/main.js b/js/main.js index 7a41fc9..d7d4688 100755 --- a/js/main.js +++ b/js/main.js @@ -384,7 +384,7 @@ function loadMapAPI(api) { var loadTime = 0; function waitAndLoad(api, url) { // wait till first script loaded - if (loadTime > 5000) { loadTime = 0; alert('Sorry, can\'t load ' + api + ' API'); return; } + if (loadTime > 5000) { loadTime = 0; alert(sprintf(lang['apifailure'], api)); return; } if (loadedAPI !== api) { setTimeout(function () { loadTime += 50; waitAndLoad(api, url); }, 50); return; @@ -398,7 +398,7 @@ function waitAndLoad(api, url) { function waitAndInit(api) { // wait till main api loads - if (loadTime > 10000) { loadTime = 0; alert('Sorry, can\'t load ' + api + ' API'); return; } + if (loadTime > 10000) { loadTime = 0; alert(sprintf(lang['apifailure'], api)); return; } try { init(); } diff --git a/js/pass.js b/js/pass.js index 0f92819..7e59688 100644 --- a/js/pass.js +++ b/js/pass.js @@ -32,11 +32,11 @@ function submitPass() { var pass = form.elements['pass'].value; var pass2 = form.elements['pass2'].value; if (!oldpass || !pass || !pass2) { - alert("All fields are required"); + alert(lang['allrequired']); return; } if (pass != pass2) { - alert("Passwords don't match"); + alert(lang['passnotmatch']); return; } var xhr = getXHR(); @@ -48,13 +48,13 @@ function submitPass() { var root = xml.getElementsByTagName('root'); if (root.length && getNode(root[0], 'error') == 0) { removeModal(); - alert("Password successfully changed"); + alert(lang["actionsuccess"]); return; } errorMsg = getNode(root[0], 'message'); if (errorMsg) { message = errorMsg; } } - alert("Something went wrong\n" + message); + alert(lang['actionfailure'] + '\n' + message); xhr = null; } } diff --git a/lang/en.php b/lang/en.php index 6563bcc..1f9e855 100644 --- a/lang/en.php +++ b/lang/en.php @@ -67,5 +67,14 @@ $lang["gps"] = "GPS"; $lang["network"] = "Network"; $lang["deluser"] = "Remove user"; $lang["edituser"] = "Edit user"; +$lang["servererror"] = "Server error"; +$lang["allrequired"] = "All fields are required"; +$lang["passnotmatch"] = "Passwords don't match"; +$lang["actionsuccess"] = "Action completed successfully"; +$lang["actionfailure"] = "Something went wrong"; +$lang["deletewarn"] = "Warning!\n\nYou are going to permanently delete user %s, together with all their routes and positions.\n\nAre you sure?"; // substitutes user login +$lang["editinguser"] = "You are editing user %s"; // substitutes user login +$lang["selfeditwarn"] = "Your can't edit your own user with this tool"; +$lang["apifailure"] = "Sorry, can't load %s API"; // substitures api name (gmaps or openlayers) ?> diff --git a/lang/pl.php b/lang/pl.php index f8117e8..c58a1e0 100644 --- a/lang/pl.php +++ b/lang/pl.php @@ -65,5 +65,14 @@ $lang["gps"] = "GPS"; $lang["network"] = "Sieć"; $lang["deluser"] = "Usuń użytkownika"; $lang["edituser"] = "Edytuj użytkownika"; +$lang["servererror"] = "Błąd serwera"; +$lang["allrequired"] = "Wszystkie pola są wymagane"; +$lang["passnotmatch"] = "Hasła nie pasują do siebie"; +$lang["actionsuccess"] = "Operacja zakończona pomyślnie"; +$lang["actionfailure"] = "Wystąpił błąd"; +$lang["deletewarn"] = "Uwaga!\n\nZamierzasz całkowicie usunąć użytkownika %s, razem ze wszystkimi jego trasami i pozycjami.\n\nCzy na pewno?"; +$lang["editinguser"] = "Edytujesz użytkownika %s"; +$lang["selfeditwarn"] = "Nie można edytować własnego użytkownika za pomocą tego narzędzia"; +$lang["apifailure"] = "Niestety ładowanie API %s nie powiodło się"; ?> diff --git a/utils/handleuser.php b/utils/handleuser.php index 2193a10..4887df3 100644 --- a/utils/handleuser.php +++ b/utils/handleuser.php @@ -45,7 +45,7 @@ $login = isset($_REQUEST['login']) ? trim($_REQUEST['login']) : NULL; $hash = isset($_REQUEST['pass']) ? password_hash($_REQUEST['pass'], PASSWORD_DEFAULT) : NULL; if (!$user->isAdmin || empty($action) || empty($login) || $user->login == $login) { - exitWithStatus(true, "Server error"); + exitWithStatus(true, $lang["servererror"]); } $aUser = new uUser($login); @@ -53,7 +53,7 @@ switch ($action) { case 'add': if (empty($hash)) { - exitWithStatus(true, "Server error"); + exitWithStatus(true, $lang["servererror"]); } if ($aUser->isValid) { exitWithStatus(true, $lang["userexists"]); @@ -66,7 +66,7 @@ case 'update': // update password if (empty($hash)) { - exitWithStatus(true, "Server error"); + exitWithStatus(true, $lang["servererror"]); } if ($aUser->setPass($hash) === false) { exitWithStatus(true, $mysqli->error); @@ -80,7 +80,7 @@ break; default: - exitWithStatus(true, "Server error"); + exitWithStatus(true, $lang["servererror"]); break; }