Allow substitutions in translated strings

This commit is contained in:
Bartek Fabiszewski 2017-04-12 21:48:40 +02:00
parent 87d760e4a2
commit 43fc46a9fc
10 changed files with 48 additions and 44 deletions

View File

@ -164,8 +164,7 @@ select {
padding-right: 20px; padding-right: 20px;
} }
#pfooter { #pfooter {
clear: both; font-size: .6rem;
font-size: smaller;
padding-top: 20px; padding-top: 20px;
} }
#bottom { #bottom {

View File

@ -190,6 +190,7 @@ function getPopupHtml(p, i, count) {
'<img class="icon" alt="' + lang['tdistance'] + '" title="' + lang['tdistance'] + '" src="images/distance_blue.svg"> ' + '<img class="icon" alt="' + lang['tdistance'] + '" title="' + lang['tdistance'] + '" src="images/distance_blue.svg"> ' +
(p.totalMeters.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '<br>' + '</div>'; (p.totalMeters.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '<br>' + '</div>';
} }
olHack = (mapapi == 'openlayers') ? ' style="padding-bottom: 2rem"' : '';
popup = popup =
'<div id="popup">' + '<div id="popup">' +
'<div id="pheader">' + '<div id="pheader">' +
@ -209,8 +210,8 @@ function getPopupHtml(p, i, count) {
(p.accuracy * factor_m).toFixed() + ' ' + unit_m + provider + '<br>' : '') + (p.accuracy * factor_m).toFixed() + ' ' + unit_m + provider + '<br>' : '') +
'</div>' + '</div>' +
stats + stats +
'<div id="pfooter">' + lang['point'] + ' ' + (i + 1) + ' ' + lang['of'] + ' ' + count + '</div>' + '</div><div id="pfooter"' + olHack + '>' + sprintf(lang['pointof'], i + 1, count) + '</div>' +
'</div></div>'; '</div>';
return popup; return popup;
} }
@ -364,6 +365,7 @@ function setTime() {
// dynamic change of map api // dynamic change of map api
var savedBounds; var savedBounds;
function loadMapAPI(api) { function loadMapAPI(api) {
mapapi = api;
savedBounds = getBounds(); savedBounds = getBounds();
document.getElementById("map-canvas").innerHTML = ''; document.getElementById("map-canvas").innerHTML = '';
var url = new Array(); var url = new Array();
@ -485,3 +487,14 @@ function removeOnClick(event) {
event.stopPropagation(); event.stopPropagation();
} }
} }
// naive approach, only %s, %d supported
function sprintf() {
var args = Array.prototype.slice.call(arguments);
var format = args.shift();
var i = 0;
return format.replace(/%%|%s|%d/g, function(match) {
if (match == '%%') { return '%'; }
return (typeof args[i] != 'undefined') ? args[i++] : match;
});
};

View File

@ -35,8 +35,7 @@ $lang["altitude"] = "Höhe";
$lang["ttime"] = "Gesamte Zeit"; $lang["ttime"] = "Gesamte Zeit";
$lang["aspeed"] = "Durchschnittstempo"; $lang["aspeed"] = "Durchschnittstempo";
$lang["tdistance"] = "Gesamt Entfernung"; $lang["tdistance"] = "Gesamt Entfernung";
$lang["point"] = "Punkt"; //Punkt x von y $lang["pointof"] = "Punkt %d von %d";
$lang["of"] = "von";
$lang["summary"] = "Streckenzusammenfassung"; $lang["summary"] = "Streckenzusammenfassung";
$lang["suser"] = "Wähle Benutzer"; $lang["suser"] = "Wähle Benutzer";
$lang["logout"] = "Abmelden"; $lang["logout"] = "Abmelden";

View File

@ -37,8 +37,7 @@ $lang["altitude"] = "Altitude";
$lang["ttime"] = "Total time"; $lang["ttime"] = "Total time";
$lang["aspeed"] = "Average speed"; $lang["aspeed"] = "Average speed";
$lang["tdistance"] = "Total distance"; $lang["tdistance"] = "Total distance";
$lang["point"] = "Point"; //Point x of y $lang["pointof"] = "Point %d of %d"; // e.g. Point 3 of 10
$lang["of"] = "of";
$lang["summary"] = "Trip summary"; $lang["summary"] = "Trip summary";
$lang["suser"] = "select user"; $lang["suser"] = "select user";
$lang["logout"] = "Log out"; $lang["logout"] = "Log out";

View File

@ -35,8 +35,7 @@ $lang["altitude"] = "Altitud";
$lang["ttime"] = "Tiempo total"; $lang["ttime"] = "Tiempo total";
$lang["aspeed"] = "Velocidad media"; $lang["aspeed"] = "Velocidad media";
$lang["tdistance"] = "Distancia total"; $lang["tdistance"] = "Distancia total";
$lang["point"] = "Punto"; //Point x of y $lang["pointof"] = "Punto %d de %d";
$lang["of"] = "de";
$lang["summary"] = "Resumen del viaje"; $lang["summary"] = "Resumen del viaje";
$lang["suser"] = "seleccione usuario"; $lang["suser"] = "seleccione usuario";
$lang["logout"] = "Cerrar sesión"; $lang["logout"] = "Cerrar sesión";

View File

@ -35,8 +35,7 @@ $lang["altitude"] = "Altitude";
$lang["ttime"] = "Temps total"; $lang["ttime"] = "Temps total";
$lang["aspeed"] = "Vitesse moyenne"; $lang["aspeed"] = "Vitesse moyenne";
$lang["tdistance"] = "Dist. totale"; $lang["tdistance"] = "Dist. totale";
$lang["point"] = "Point"; //Point x of y $lang["pointof"] = "Point %d de %d";
$lang["of"] = "de";
$lang["summary"] = "Résumé du trajet"; $lang["summary"] = "Résumé du trajet";
$lang["suser"] = "Sélectionner un utilisateur"; $lang["suser"] = "Sélectionner un utilisateur";
$lang["logout"] = "Déconnexion"; $lang["logout"] = "Déconnexion";

View File

@ -36,8 +36,7 @@ $lang["ttime"] = "Menetidő";
$lang["aspeed"] = "Átlagsebesség"; $lang["aspeed"] = "Átlagsebesség";
$lang["tdistance"] = "Megtett út"; $lang["tdistance"] = "Megtett út";
$lang["suser"] = "Felhasználónév"; $lang["suser"] = "Felhasználónév";
$lang["point"] = "Rögzített pontok száma"; $lang["pointof"] = "Rögzített pontok száma %d / %d";
$lang["of"] = "/";
$lang["summary"] = "Utazás adatai"; $lang["summary"] = "Utazás adatai";
$lang["logout"] = "Kilépés"; $lang["logout"] = "Kilépés";
$lang["login"] = "Belépés"; $lang["login"] = "Belépés";

View File

@ -35,8 +35,7 @@ $lang["altitude"] = "Altitudine";
$lang["ttime"] = "Tempo totale"; $lang["ttime"] = "Tempo totale";
$lang["aspeed"] = "Velocità media"; $lang["aspeed"] = "Velocità media";
$lang["tdistance"] = "Distanza totale"; $lang["tdistance"] = "Distanza totale";
$lang["point"] = "Punto"; //Point x of y $lang["point"] = "Punto %d di %d";
$lang["of"] = "di";
$lang["summary"] = "Sommario"; $lang["summary"] = "Sommario";
$lang["suser"] = "scegli utente"; $lang["suser"] = "scegli utente";
$lang["logout"] = "Esci"; $lang["logout"] = "Esci";

View File

@ -36,8 +36,7 @@ $lang["ttime"] = "Czas podróży";
$lang["aspeed"] = "Średnia prędkość"; $lang["aspeed"] = "Średnia prędkość";
$lang["tdistance"] = "Odległość"; $lang["tdistance"] = "Odległość";
$lang["suser"] = "wybierz login"; $lang["suser"] = "wybierz login";
$lang["point"] = "Punkt"; $lang["pointof"] = "Punkt %d z %d";
$lang["of"] = "z";
$lang["summary"] = "Podsumowanie"; $lang["summary"] = "Podsumowanie";
$lang["logout"] = "Wyloguj"; $lang["logout"] = "Wyloguj";
$lang["login"] = "Zaloguj"; $lang["login"] = "Zaloguj";

View File

@ -29,9 +29,9 @@ require_once(ROOT_DIR . "/helpers/position.php");
*/ */
function addStyle($xml, $name, $url) { function addStyle($xml, $name, $url) {
$xml->startElement("Style"); $xml->startElement("Style");
$xml->writeAttribute("id", $name."Style"); $xml->writeAttribute("id", "{$name}Style");
$xml->startElement("IconStyle"); $xml->startElement("IconStyle");
$xml->writeAttribute("id", $name."Icon"); $xml->writeAttribute("id", "{$name}Icon");
$xml->startElement("Icon"); $xml->startElement("Icon");
$xml->writeElement("href", $url); $xml->writeElement("href", $url);
$xml->endElement(); $xml->endElement();
@ -50,7 +50,7 @@ function toHMS($s) {
$h = floor(($s % 86400) / 3600); $h = floor(($s % 86400) / 3600);
$m = floor((($s % 86400) % 3600) / 60); $m = floor((($s % 86400) % 3600) / 60);
$s = (($s % 86400) % 3600) % 60; $s = (($s % 86400) % 3600) % 60;
return (($d > 0) ? ($d." d ") : "").(substr("00".$h, -2)).":".(substr("00".$m, -2)).":".(substr("00".$s, -2)); return (($d > 0) ? "$d d " : "") . sprintf("%02d:%02d:%02d", $h, $m, $s);
} }
$type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : "kml"; $type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : "kml";
@ -92,7 +92,7 @@ if ($trackId && $userId) {
case "kml": case "kml":
default: default:
header("Content-type: application/vnd.google-earth.kml+xml"); header("Content-type: application/vnd.google-earth.kml+xml");
header("Content-Disposition: attachment; filename=\"track" . $positionsArr[0]->trackId . ".kml\""); header("Content-Disposition: attachment; filename=\"track{$positionsArr[0]->trackId}.kml\"");
$xml = new XMLWriter(); $xml = new XMLWriter();
$xml->openURI("php://output"); $xml->openURI("php://output");
$xml->setIndent(true); $xml->setIndent(true);
@ -128,26 +128,26 @@ if ($trackId && $userId) {
if(++$i == count($positionsArr)) { $style = "#greenStyle"; } // last element if(++$i == count($positionsArr)) { $style = "#greenStyle"; } // last element
$xml->startElement("Placemark"); $xml->startElement("Placemark");
$xml->writeAttribute("id", "point_" . $position->id); $xml->writeAttribute("id", "point_{$position->id}");
$description = $description =
"<div style=\"font-weight: bolder; padding-bottom: 10px; border-bottom: 1px solid gray;\">" . "<div style=\"font-weight: bolder; padding-bottom: 10px; border-bottom: 1px solid gray;\">" .
$lang["user"].": ".strtoupper($position->userLogin)."<br>".$lang["track"].": ".strtoupper($position->trackName). "{$lang["user"]}: {$position->userLogin}<br>{$lang["track"]}: {$position->trackName}" .
"</div>" . "</div>" .
"<div>" . "<div>" .
"<div style=\"padding-top: 10px;\"><b>".$lang["time"].":</b> ".$position->time."<br>". "<div style=\"padding-top: 10px;\"><b>{$lang["time"]}:</b> {$position->time}<br>" .
(!is_null($position->speed) ? "<b>".$lang["speed"].":</b> ".round($position->speed * 3.6 * $factor_kmh, 2)." ".$unit_kmh."<br>" : ""). (!is_null($position->speed) ? "<b>{$lang["speed"]}:</b> " . round($position->speed * 3.6 * $factor_kmh, 2) . " {$unit_kmh}<br>" : "") .
(!is_null($position->altitude) ? "<b>".$lang["altitude"].":</b> ".round($position->altitude * $factor_m)." ".$unit_m."<br>" : ""). (!is_null($position->altitude) ? "<b>{$lang["altitude"]}:</b> " . round($position->altitude * $factor_m) . " {$unit_m}<br>" : "") .
"<b>".$lang["ttime"].":</b> ".toHMS($totalSeconds)."<br>". "<b>{$lang["ttime"]}:</b> " . toHMS($totalSeconds) . "<br>" .
"<b>".$lang["aspeed"].":</b> ".(($totalSeconds != 0) ? round($totalMeters / $totalSeconds * 3.6 * $factor_kmh, 2) : 0)." ".$unit_kmh."<br>". "<b>{$lang["aspeed"]}:</b> " . (($totalSeconds != 0) ? round($totalMeters / $totalSeconds * 3.6 * $factor_kmh, 2) : 0) . " {$unit_kmh}<br>" .
"<b>".$lang["tdistance"].":</b> ".round($totalMeters / 1000 * $factor_km, 2)." ".$unit_km."<br>"."</div>". "<b>{$lang["tdistance"]}:</b> " . round($totalMeters / 1000 * $factor_km, 2) . " " . $unit_km . "<br></div>" .
"<div style=\"font-size: smaller;padding-top: 10px;\">".$lang["point"]." ".$i." ".$lang["of"]." ".count($positionsArr)."</div>". "<div style=\"font-size: smaller; padding-top: 10px;\">" . sprintf($lang["pointof"], $i, count($positionsArr)) . "</div>" .
"</div>"; "</div>";
$xml->startElement("description"); $xml->startElement("description");
$xml->writeCData($description); $xml->writeCData($description);
$xml->endElement(); $xml->endElement();
$xml->writeElement("styleUrl", $style); $xml->writeElement("styleUrl", $style);
$xml->startElement("Point"); $xml->startElement("Point");
$coordinate[$i] = $position->longitude.",".$position->latitude.(!is_null($position->altitude) ? ",".$position->altitude : ""); $coordinate[$i] = "{$position->longitude},{$position->latitude}" . (!is_null($position->altitude) ? ",{$position->altitude}" : "");
$xml->writeElement("coordinates", $coordinate[$i]); $xml->writeElement("coordinates", $coordinate[$i]);
$xml->endElement(); $xml->endElement();
$xml->endElement(); $xml->endElement();
@ -206,14 +206,13 @@ if ($trackId && $userId) {
$xml->writeElement("name", ++$i); $xml->writeElement("name", ++$i);
$xml->startElement("desc"); $xml->startElement("desc");
$description = $description =
$lang["user"].": ".strtoupper($position->userLogin)." ".$lang["track"].": ".strtoupper($position->trackName). "{$lang["user"]}: {$position->userLogin} {$lang["track"]}: {$position->trackName} {$lang["time"]}: {$position->time}" .
" ".$lang["time"].": ".$position->time. (!is_null($position->speed) ? " {$lang["speed"]}: " . round($position->speed * 3.6 * $factor_kmh, 2) . " {$unit_kmh}" : "") .
(!is_null($position->speed) ? " ".$lang["speed"].": ".round($position->speed * 3.6 * $factor_kmh, 2)." ".$unit_kmh : ""). (!is_null($position->altitude) ? " {$lang["altitude"]}: " . round($position->altitude * $factor_m) . " {$unit_m}" : "") .
(!is_null($position->altitude) ? " ".$lang["altitude"].": ".round($position->altitude * $factor_m)." ".$unit_m : ""). " {$lang["ttime"]}: " . toHMS($totalSeconds) .
" ".$lang["ttime"].": ".toHMS($totalSeconds)."". " {$lang["aspeed"]}: " . (($totalSeconds != 0) ? round($totalMeters / $totalSeconds * 3.6 * $factor_kmh, 2) : 0) . " {$unit_kmh}" .
" ".$lang["aspeed"].": ".(($totalSeconds != 0) ? round($totalMeters / $totalSeconds * 3.6 * $factor_kmh, 2) : 0)." ".$unit_kmh. " {$lang["tdistance"]}: " . round($totalMeters / 1000 * $factor_km, 2) . " {$unit_km}" .
" ".$lang["tdistance"].": ".round($totalMeters / 1000 * $factor_km, 2)." ".$unit_km. " " . sprintf($lang["pointof"], $i, count($positionsArr));
" ".$lang["point"]." ".$i." ".$lang["of"]." ".count($positionsArr);
$xml->writeCData($description); $xml->writeCData($description);
$xml->endElement(); $xml->endElement();
$xml->endElement(); $xml->endElement();