Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark more strings for translation #691

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions js/ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ class IDE {
if (typeof abortCallback == "function") {
this.onAbort = abortCallback;
const aborter = $(
'<span id="aborter">&nbsp;(<a href="#">abort</a>)</span>'
`<span id="aborter">&nbsp;(<a href="#">${i18n.t(
"waiter.abort"
)}</a>)</span>`
).on("click", () => {
this.abort();
return false;
Expand All @@ -214,7 +216,7 @@ class IDE {
}
abort() {
if (typeof this.onAbort == "function") {
this.addInfo("aborting");
this.addInfo(i18n.t("waiter.aborting"));
this.onAbort(this.close);
}
}
Expand Down Expand Up @@ -269,7 +271,7 @@ class IDE {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const ide = this;
// parse url string parameters
ide.waiter.addInfo("parse url parameters");
ide.waiter.addInfo(i18n.t("waiter.parse_url_parameters"));
const args = urlParameters();
// set appropriate settings
if (args.has_coords) {
Expand All @@ -287,7 +289,7 @@ class IDE {
}
settings.save();

ide.waiter.addInfo("initialize page");
ide.waiter.addInfo(i18n.t("waiter.initialize_page"));
// init page layout
const isInitialAspectPortrait =
$(window).width() / $(window).height() < 0.8;
Expand Down Expand Up @@ -468,7 +470,7 @@ class IDE {
}
// init dataviewer
ide.dataViewer = CodeMirror($("#data")[0], {
value: "no data loaded yet",
value: i18n.t("editor.no_data_loaded"),
lineNumbers: true,
readOnly: true,
mode: "javascript"
Expand Down Expand Up @@ -865,7 +867,7 @@ class IDE {
const isCountPresent = /out[^;]+?count/.test(query);

// show warning/info if only invisible data is returned and 'out...count' is not present in the query
if (empty_msg == "no visible data") {
if (empty_msg == "waiter.no_visible_data") {
if (!isCountPresent && !settings.no_autorepair) {
const content = `<p>${i18n.t(
"warning.incomplete.expl.1"
Expand Down Expand Up @@ -905,16 +907,16 @@ class IDE {
}
}
// auto tab switching (if only areas are returned)
if (empty_msg == "only areas returned") ide.switchTab("Data");
if (empty_msg == "waiter.only_areas_returned") ide.switchTab("Data");
// auto tab switching (if nodes without coordinates are returned)
if (empty_msg == "no coordinates returned") ide.switchTab("Data");
if (empty_msg == "waiter.no_coordinates_returned") ide.switchTab("Data");
// auto tab switching (if unstructured data is returned)
if (data_mode == "unknown") ide.switchTab("Data");
// display empty map badge
$(
`<div id="map_blank" style="z-index:700; display:block; position:relative; top:50px; width:100%; text-align:center; background-color:#eee; opacity: 0.8;">${i18n.t(
"map.intentionally_blank"
)} <small>(${empty_msg})</small></div>`
)} <small>(${i18n.t(empty_msg)})</small></div>`
).appendTo("#map");
};
overpass.handlers["onDataReceived"] = function (
Expand Down Expand Up @@ -2211,14 +2213,14 @@ class IDE {
// 1. render canvas from map tiles
// hide map controlls in this step :/
// todo: also hide popups?
this.waiter.addInfo("prepare map");
this.waiter.addInfo(i18n.t("waiter.prepare_map"));
$("#map .leaflet-control-container .leaflet-top").hide();
$("#data_stats").hide();
if (settings.export_image_attribution)
this.map.addControl(this.attribControl);
if (!settings.export_image_scale) this.map.removeControl(this.scaleControl);
// try to use crossOrigin image loading. osm tiles should be served with the appropriate headers -> no need of bothering the proxy
this.waiter.addInfo("rendering map tiles");
this.waiter.addInfo(i18n.t("waiter.rendering_map_tiles"));
$("#map .leaflet-overlay-pane").hide();
const canvas = await html2canvas(document.getElementById("map"), {
useCORS: true,
Expand All @@ -2231,7 +2233,7 @@ class IDE {
if (!settings.export_image_scale) this.map.addControl(this.scaleControl);
if (settings.show_data_stats) $("#data_stats").show();
$("#map .leaflet-control-container .leaflet-top").show();
this.waiter.addInfo("rendering map data");
this.waiter.addInfo(i18n.t("waiter.rendering_map_data"));
// 2. render overlay data onto canvas
canvas.id = "render_canvas";
const ctx = canvas.getContext("2d");
Expand All @@ -2257,7 +2259,7 @@ class IDE {
});
v.render();
}
this.waiter.addInfo("converting to png image");
this.waiter.addInfo(i18n.t("waiter.converting_to_png_image"));
// 3. export canvas as html image
const imgstr = canvas.toDataURL("image/png");
let attrib_message = "";
Expand Down Expand Up @@ -2585,7 +2587,7 @@ class IDE {
}
async update_map() {
this.waiter.open(i18n.t("waiter.processing_query"));
this.waiter.addInfo("resetting map");
this.waiter.addInfo(i18n.t("waiter.resetting_map"));
$("#data_stats").remove();
// resets previously highlighted error lines
this.resetErrors();
Expand All @@ -2595,7 +2597,7 @@ class IDE {
this.map.removeLayer(overpass.osmLayer);
$("#map_blank").remove();

this.waiter.addInfo("building query");
this.waiter.addInfo(i18n.t("waiter.building_query"));
// run the query via the overpass object
const query = await this.getQuery();
if (configs.push_history_url && typeof history.pushState == "function") {
Expand Down
91 changes: 55 additions & 36 deletions js/overpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import L_OSM4Leaflet from "./OSM4Leaflet";
import L_GeoJsonNoVanish from "./GeoJsonNoVanish";

import configs from "./configs";
import i18n from "./i18n";
import settings from "./settings";
import {htmlentities} from "./misc";
import styleparser from "./jsmapcss";
Expand Down Expand Up @@ -80,21 +81,17 @@ class Overpass {
query = `<?xml version="1.0" encoding="UTF-8"?>${query}`;
}
}
overpass.fire(
"onProgress",
"calling Overpass API interpreter",
(callback) => {
// kill the query on abort
overpass.ajax_request.abort();
// try to abort queries via kill_my_queries
$.get(`${server}kill_my_queries`)
.done(callback)
.fail(() => {
console.log("Warning: failed to kill query.");
callback();
});
}
);
overpass.fire("onProgress", i18n.t("waiter.calling_api"), (callback) => {
// kill the query on abort
overpass.ajax_request.abort();
// try to abort queries via kill_my_queries
$.get(`${server}kill_my_queries`)
.done(callback)
.fail(() => {
console.log("Warning: failed to kill query.");
callback();
});
});
function onSuccessCb(data, textStatus, jqXHR) {
//textStatus is not needed in the successCallback, don't cache it
if (cache) cache[query] = [data, undefined, jqXHR];
Expand All @@ -105,10 +102,15 @@ class Overpass {
const scale = Math.floor(Math.log(data_amount) / Math.log(10));
data_amount =
Math.round(data_amount / Math.pow(10, scale)) * Math.pow(10, scale);
if (data_amount < 1000) data_txt = `${data_amount} bytes`;
else if (data_amount < 1000000) data_txt = `${data_amount / 1000} kB`;
else data_txt = `${data_amount / 1000000} MB`;
overpass.fire("onProgress", `received about ${data_txt} of data`);
if (data_amount < 1000)
data_txt = `${data_amount} ${i18n.t("waiter.bytes")}`;
else if (data_amount < 1000000)
data_txt = `${data_amount / 1000} ${i18n.t("waiter.kilobytes")}`;
else data_txt = `${data_amount / 1000000} ${i18n.t("waiter.megabytes")}`;
overpass.fire(
"onProgress",
i18n.t("waiter.received_data").replace("{{data_amount}}", data_txt)
);
overpass.fire(
"onDataReceived",
data_amount,
Expand Down Expand Up @@ -138,7 +140,7 @@ class Overpass {
};
overpass.ajax_request_duration =
Date.now() - overpass.ajax_request_start;
overpass.fire("onProgress", "parsing data");
overpass.fire("onProgress", i18n.t("waiter.parsing_data"));
setTimeout(() => {
// hacky firefox hack :( (it is not properly detecting json from the content-type header)
if (typeof data == "string" && data[0] == "{") {
Expand Down Expand Up @@ -418,7 +420,7 @@ class Overpass {

overpass.osmLayer = new L_OSM4Leaflet(null, {
afterParse() {
overpass.fire("onProgress", "rendering geoJSON");
overpass.fire("onProgress", i18n.t("waiter.rendering"));
},
baseLayerClass: L_GeoJsonNoVanish,
baseLayerOptions: {
Expand Down Expand Up @@ -631,7 +633,10 @@ class Overpass {
if (!shouldCacheOnly) overpass.fire("onGeoJsonReady");

// print raw data
overpass.fire("onProgress", "printing raw data");
overpass.fire(
"onProgress",
i18n.t("waiter.printing_raw_data")
);
setTimeout(() => {
overpass.resultText = jqXHR.responseText;
overpass.fire("onRawDataPresent");
Expand All @@ -657,15 +662,15 @@ class Overpass {
.children()
.not("note,meta,bounds,area").length == 0)
)
empty_msg = "only areas returned";
empty_msg = "waiter.only_areas_returned";
else if (
(data_mode == "json" &&
_.some(data.elements, {type: "node"})) ||
(data_mode == "xml" &&
$("osm", data).children().filter("node").length > 0)
)
// check for "ids_only" or "tags" on nodes
empty_msg = "no coordinates returned";
empty_msg = "waiter.no_coordinates_returned";
else if (
(data_mode == "json" &&
_.some(data.elements, {type: "way"}) &&
Expand All @@ -683,7 +688,7 @@ class Overpass {
.filter("nd").length == 0)
)
// check for "ids_only" or "tags" on ways
empty_msg = "no coordinates returned";
empty_msg = "waiter.no_coordinates_returned";
else if (
(data_mode == "json" &&
_.some(data.elements, {type: "relation"}) &&
Expand All @@ -701,14 +706,14 @@ class Overpass {
.filter("member").length == 0)
)
// check for "ids_only" or "tags" on relations
empty_msg = "no coordinates returned";
else empty_msg = "no visible data";
empty_msg = "waiter.no_coordinates_returned";
else empty_msg = "waiter.no_visible_data";
} else if (data_mode == "error") {
empty_msg = "an error occured";
empty_msg = "waiter.an_error_occured";
} else if (data_mode == "unknown") {
empty_msg = "unstructured data returned";
empty_msg = "waiter.unstructured_data_returned";
} else {
empty_msg = "received empty dataset";
empty_msg = "waiter.received_empty_dataset";
}
// show why there is an empty map
overpass.fire("onEmptyMap", empty_msg, data_mode);
Expand Down Expand Up @@ -736,7 +741,7 @@ class Overpass {
success: onSuccessCb,
error(jqXHR, textStatus) {
if (textStatus == "abort") return; // ignore aborted queries.
overpass.fire("onProgress", "error during ajax call");
overpass.fire("onProgress", i18n.t("waiter.error_during_ajax_call"));
if (
jqXHR.status == 400 ||
jqXHR.status == 504 ||
Expand All @@ -750,17 +755,31 @@ class Overpass {
overpass.resultText = jqXHR.resultText;
let errmsg = "";
if (jqXHR.state() == "rejected")
errmsg +=
"<p>Request rejected. (e.g. server not found, request blocked by browser addon, request redirected, internal server errors, etc.)</p>";
errmsg += "<p>" + i18n.t("waiter.request_rejected") + "</p>";
if (textStatus == "parsererror")
errmsg += "<p>Error while parsing the data (parsererror).</p>";
errmsg +=
"<p>" +
i18n
.t("waiter.parse_error")
.replace("{{textStatus}}", textStatus) +
"</p>";
else if (textStatus != "error" && textStatus != jqXHR.statusText)
errmsg += `<p>Error-Code: ${textStatus}</p>`;
errmsg +=
"<p>" +
i18n
.t("waiter.error_code")
.replace("{{textStatus}}", textStatus) +
"</p>";
if (
(jqXHR.status != 0 && jqXHR.status != 200) ||
jqXHR.statusText != "OK" // note to me: jqXHR.status "should" give http status codes
)
errmsg += `<p>Error-Code: ${jqXHR.statusText} (${jqXHR.status})</p>`;
errmsg +=
"<p>" +
i18n
.t("waiter.error_code")
.replace("{{textStatus}}", jqXHR.statusText) +
` (${jqXHR.status})</p>`;
overpass.fire("onAjaxError", errmsg);
// closing wait spinner
overpass.fire("onDone");
Expand Down
Loading