Zmiana aplikacji na wersje lang
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { endpoints, geoBypassHosts } from "./config.js";
|
||||
import { t } from "./i18n.js";
|
||||
import { trackEvent } from "./analytics.js";
|
||||
import {
|
||||
runPendingProtectedAction,
|
||||
@@ -109,21 +110,15 @@ function showGreeting(name, firstVisitTime) {
|
||||
}
|
||||
}
|
||||
|
||||
function isIOSDevice() {
|
||||
return (
|
||||
/iPad|iPhone|iPod/.test(navigator.userAgent) ||
|
||||
(navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)
|
||||
);
|
||||
function GEO_GATE_LABELS() {
|
||||
return {
|
||||
status: t("geo.feature.status"),
|
||||
waiter: t("geo.feature.waiter"),
|
||||
bill: t("geo.feature.bill"),
|
||||
};
|
||||
}
|
||||
|
||||
const GEO_GATE_LABELS = {
|
||||
status: "status zamówienia",
|
||||
waiter: "wezwanie kelnera",
|
||||
bill: "prośbę o rachunek",
|
||||
};
|
||||
|
||||
const GEO_DEFAULT_LEAD =
|
||||
"Przeglądaj menu od razu — albo potwierdź, że jesteś u nas, aby wezwać kelnera, śledzić zamówienie i poprosić o rachunek.";
|
||||
const GEO_DEFAULT_LEAD = () => t("geo.lead");
|
||||
|
||||
function setGeoLead(html) {
|
||||
const el = document.getElementById("geoLead");
|
||||
@@ -155,7 +150,7 @@ function setGeoActionBusy(busy) {
|
||||
btn.disabled = false;
|
||||
btn.setAttribute("aria-busy", busy ? "true" : "false");
|
||||
if (busy) {
|
||||
setGeoActionLabel("Sprawdzanie…");
|
||||
setGeoActionLabel(t("geo.btn.checking"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,19 +167,7 @@ function setGeoActionLabel(text) {
|
||||
}
|
||||
|
||||
function getGeoPermissionInstructions() {
|
||||
if (isIOSDevice()) {
|
||||
return `<b>iPhone (Safari):</b><br>
|
||||
1. Kliknij <b>aA</b> po lewej stronie paska adresu.<br>
|
||||
2. Wybierz <b>Ustawienia witryny</b>.<br>
|
||||
3. Ustaw <b>Położenie</b> na „Zapytaj” lub „Pozwalaj”.<br>
|
||||
4. Odśwież stronę.<br><br>
|
||||
<i>Lokalizacja działa tylko przez bezpieczne <b>https://</b>.</i>`;
|
||||
}
|
||||
|
||||
return `<b>Android / Chrome:</b><br>
|
||||
1. Kliknij ikonę <b>kłódki</b> obok adresu strony.<br>
|
||||
2. W <b>Uprawnieniach</b> zmień Lokalizację na „Zezwalaj”.<br>
|
||||
3. Odśwież stronę.`;
|
||||
return t("geo.hint.permission");
|
||||
}
|
||||
|
||||
let geoMenuButtonMode = "menu_only";
|
||||
@@ -231,7 +214,7 @@ function configureGeoSecondaryButton(mode) {
|
||||
|
||||
if (mode === "back_to_menu") {
|
||||
menuOnlyBtn.style.display = "";
|
||||
if (mainEl) mainEl.textContent = "Wróć do menu";
|
||||
if (mainEl) mainEl.textContent = t("geo.btn.back_menu");
|
||||
if (subEl) {
|
||||
subEl.textContent = "";
|
||||
subEl.style.display = "none";
|
||||
@@ -240,9 +223,9 @@ function configureGeoSecondaryButton(mode) {
|
||||
}
|
||||
|
||||
menuOnlyBtn.style.display = "";
|
||||
if (mainEl) mainEl.textContent = "Przejdź do menu";
|
||||
if (mainEl) mainEl.textContent = t("geo.btn.menu_main");
|
||||
if (subEl) {
|
||||
subEl.textContent = "bez lokalizacji";
|
||||
subEl.textContent = t("geo.btn.menu_sub");
|
||||
subEl.style.display = "";
|
||||
}
|
||||
}
|
||||
@@ -255,13 +238,13 @@ export function showGeoGateForAction(action) {
|
||||
if (loadingScreen) loadingScreen.classList.add("hidden");
|
||||
if (geoScreen) geoScreen.classList.remove("hidden");
|
||||
|
||||
const feature = GEO_GATE_LABELS[action] || "tę funkcję";
|
||||
setGeoLead(`Menu masz już otwarte. Aby skorzystać z <b>${feature}</b>, potwierdź krótko, że jesteś w restauracji.`);
|
||||
const feature = GEO_GATE_LABELS()[action] || t("geo.feature.other");
|
||||
setGeoLead(t("geo.lead_action", { feature }));
|
||||
setGeoStatus("");
|
||||
hideGeoInstructions();
|
||||
if (geoActionBtn) {
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Sprawdź lokalizację");
|
||||
setGeoActionLabel(t("geo.btn.check"));
|
||||
}
|
||||
configureGeoSecondaryButton(getAppAccessLevel() === "menu" ? "back_to_menu" : "menu_only");
|
||||
}
|
||||
@@ -425,24 +408,22 @@ function showGeoConsentScreen() {
|
||||
loadingScreen.classList.add("hidden");
|
||||
geoScreen.classList.remove("hidden");
|
||||
|
||||
setGeoLead(GEO_DEFAULT_LEAD);
|
||||
setGeoLead(GEO_DEFAULT_LEAD());
|
||||
setGeoStatus("");
|
||||
hideGeoInstructions();
|
||||
|
||||
if (geoActionBtn) {
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Zgoda, sprawdź lokalizację");
|
||||
setGeoActionLabel(t("geo.btn.locate"));
|
||||
}
|
||||
configureGeoSecondaryButton("menu_only");
|
||||
}
|
||||
|
||||
function showGeoPermissionBlockedState() {
|
||||
setGeoStatus("Przeglądarka zablokowała dostęp do lokalizacji.", { error: true });
|
||||
showGeoInstructions(
|
||||
`${getGeoPermissionInstructions()}<br><br>Po zmianie ustawień <b>odśwież stronę</b>, a potem kliknij „Spróbuj ponownie”.`
|
||||
);
|
||||
setGeoStatus(t("geo.status.blocked"), { error: true });
|
||||
showGeoInstructions(getGeoPermissionInstructions());
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Spróbuj ponownie");
|
||||
setGeoActionLabel(t("geo.btn.retry"));
|
||||
configureGeoSecondaryButton(getAppAccessLevel() === "menu" ? "back_to_menu" : "menu_only");
|
||||
}
|
||||
|
||||
@@ -539,26 +520,24 @@ export async function initGeolocationAfterBypassChecks(options = {}) {
|
||||
configureGeoSecondaryButton(getAppAccessLevel() === "menu" ? "back_to_menu" : "menu_only");
|
||||
|
||||
if (!window.isSecureContext) {
|
||||
setGeoLead(GEO_DEFAULT_LEAD);
|
||||
setGeoStatus("Ta strona wymaga bezpiecznego połączenia HTTPS.", { error: true });
|
||||
showGeoInstructions(
|
||||
"Przeglądarki mobilne blokują geolokalizację bez <b>https://</b>. Otwórz aplikację przez HTTPS i spróbuj ponownie."
|
||||
);
|
||||
setGeoLead(GEO_DEFAULT_LEAD());
|
||||
setGeoStatus(t("geo.status.https"), { error: true });
|
||||
showGeoInstructions(t("geo.hint.https"));
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Spróbuj ponownie");
|
||||
setGeoActionLabel(t("geo.btn.retry"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!navigator.geolocation) {
|
||||
setGeoLead(GEO_DEFAULT_LEAD);
|
||||
setGeoStatus("Twoja przeglądarka nie wspiera geolokalizacji.", { error: true });
|
||||
setGeoLead(GEO_DEFAULT_LEAD());
|
||||
setGeoStatus(t("geo.status.unsupported"), { error: true });
|
||||
hideGeoInstructions();
|
||||
setGeoActionBusy(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setGeoLead(GEO_DEFAULT_LEAD);
|
||||
setGeoStatus("Sprawdzamy Twoją lokalizację…", { info: true });
|
||||
setGeoLead(GEO_DEFAULT_LEAD());
|
||||
setGeoStatus(t("geo.status.checking"), { info: true });
|
||||
hideGeoInstructions();
|
||||
setGeoActionBusy(true);
|
||||
|
||||
@@ -595,16 +574,16 @@ export async function initGeolocationAfterBypassChecks(options = {}) {
|
||||
accuracyMeters: Math.round(accuracy),
|
||||
});
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Spróbuj ponownie");
|
||||
setGeoActionLabel(t("geo.btn.retry"));
|
||||
configureGeoSecondaryButton(getAppAccessLevel() === "menu" ? "back_to_menu" : "menu_only");
|
||||
setGeoStatus(
|
||||
`Wygląda na to, że jesteś poza restauracją (ok. ${Math.round(dist)} m, dokładność GPS: ±${Math.round(accuracy)} m).`,
|
||||
t("geo.status.outside", {
|
||||
dist: Math.round(dist),
|
||||
accuracy: Math.round(accuracy),
|
||||
}),
|
||||
{ error: true }
|
||||
);
|
||||
showGeoInstructions(
|
||||
"Przeglądarka często podaje inną lokalizację niż aplikacja Map Google. " +
|
||||
"Spróbuj ponownie na zewnątrz lub bliżej okna — albo przejdź do menu bez lokalizacji."
|
||||
);
|
||||
showGeoInstructions(t("geo.hint.outside"));
|
||||
} catch (error) {
|
||||
trackEvent("geo_check_failed", {
|
||||
reason: "browser_error",
|
||||
@@ -612,18 +591,18 @@ export async function initGeolocationAfterBypassChecks(options = {}) {
|
||||
message: String(error.message || ""),
|
||||
});
|
||||
setGeoActionBusy(false);
|
||||
setGeoActionLabel("Spróbuj ponownie");
|
||||
setGeoActionLabel(t("geo.btn.retry"));
|
||||
configureGeoSecondaryButton(getAppAccessLevel() === "menu" ? "back_to_menu" : "menu_only");
|
||||
const deniedBecauseInsecure = /secure origins|only secure|https/i.test(String(error.message || ""));
|
||||
|
||||
if (deniedBecauseInsecure) {
|
||||
setGeoStatus("Geolokalizacja wymaga HTTPS.", { error: true });
|
||||
showGeoInstructions("Otwórz aplikację przez bezpieczny adres <b>https://</b> i spróbuj ponownie.");
|
||||
setGeoStatus(t("geo.status.https_short"), { error: true });
|
||||
showGeoInstructions(t("geo.hint.https"));
|
||||
} else if (isGeoPermissionDenied(error)) {
|
||||
showGeoPermissionBlockedState();
|
||||
} else {
|
||||
setGeoStatus("Nie udało się pobrać lokalizacji.", { error: true });
|
||||
showGeoInstructions("Sprawdź zasięg, włącz GPS i spróbuj ponownie.");
|
||||
setGeoStatus(t("geo.status.failed"), { error: true });
|
||||
showGeoInstructions(t("geo.hint.retry"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user