Extract strings to lang files

This commit is contained in:
Bartek Fabiszewski 2017-04-12 22:42:23 +02:00
parent 43fc46a9fc
commit a3eed0d758
6 changed files with 37 additions and 19 deletions

View File

@ -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 = '<div style="float:left">You are editing user <b>' + userLogin + '</b></div>';
message += '<div class="red-button"><b><a href="javascript:void(0);" onclick="submitUser(\'delete\'); return false">Delete user</a></b></div>';
var message = '<div style="float:left">' + sprintf(lang['editinguser'], '<b>' + userLogin + '</b>') + '</div>';
message += '<div class="red-button"><b><a href="javascript:void(0);" onclick="submitUser(\'delete\'); return false">' + lang['deluser'] + '</a></b></div>';
message += '<div style="clear: both; padding-bottom: 1em;"></div>';
var form = '<form id="userForm" method="post" onsubmit="submitUser(\'update\'); return false">';
@ -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;
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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)
?>

View File

@ -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ę";
?>

View File

@ -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;
}