diff --git a/fireworks_detect/__pycache__/views.cpython-312.pyc b/fireworks_detect/__pycache__/views.cpython-312.pyc index 3ffa1d9..570a1ec 100644 Binary files a/fireworks_detect/__pycache__/views.cpython-312.pyc and b/fireworks_detect/__pycache__/views.cpython-312.pyc differ diff --git a/fireworks_detect/templates/fireworks_detect/manual_pending_submission.html b/fireworks_detect/templates/fireworks_detect/manual_pending_submission.html index 8c7a58e..fe56eff 100644 --- a/fireworks_detect/templates/fireworks_detect/manual_pending_submission.html +++ b/fireworks_detect/templates/fireworks_detect/manual_pending_submission.html @@ -11,7 +11,7 @@

{{ pending.created_at|date:"H:i" }} · {% blocktrans count count=pending.occurrences %}{{ count }} occurrence{% plural %}{{ count }} occurrences{% endblocktrans %} - {% if pending.direction_degrees is not None %} · {{ pending.direction_cardinal }} {{ pending.direction_degrees|floatformat:0 }}°{% endif %} + {% if direction_label %} · {{ direction_label }} {{ pending.direction_degrees|floatformat:0 }}°{% endif %}

{% endif %} diff --git a/fireworks_detect/tests.py b/fireworks_detect/tests.py index 39eaf9d..6e8646d 100644 --- a/fireworks_detect/tests.py +++ b/fireworks_detect/tests.py @@ -185,6 +185,19 @@ class ManualPendingEventTests(TestCase): self.assertContains(closed, 'id="manual-direction-summary"') self.assertNotContains(closed, 'id="manual-capture-direction"') + def test_dutch_report_labels_and_direction_are_translated(self): + self.client.cookies["django_language"] = "nl" + page = self.client.get(reverse("hello")) + self.assertContains(page, "Hoe vaak hoorde je het?") + self.assertContains(page, "Ik hoorde vuurwerk") + self.assertContains(page, "Start luisteren") + + response = self.client.post(reverse("fireworks_detect:submit_manual_pending"), { + "occurrences": "1", "direction_degrees": "192", + }) + self.assertContains(response, "Melding ontvangen!") + self.assertContains(response, "Zuid 192°") + def test_old_route_preserves_the_previous_landing_page(self): response = self.client.get(reverse("old_home")) @@ -294,7 +307,7 @@ class ManualPendingEventTests(TestCase): }) self.assertContains(response, "2 occurrences") - self.assertContains(response, "SW 237°") + self.assertContains(response, "Southwest 237°") self.assertEqual(response.status_code, 200) pending = PendingEvent.objects.get() diff --git a/fireworks_detect/views.py b/fireworks_detect/views.py index d57a0dd..c9cb6c9 100644 --- a/fireworks_detect/views.py +++ b/fireworks_detect/views.py @@ -415,7 +415,14 @@ def submit_manual_pending_event(request): direction_accuracy_degrees=direction_accuracy_degrees, direction_source="device_compass" if direction_degrees is not None else "", ) - return render(request, "fireworks_detect/manual_pending_submission.html", {"pending": pending}) + direction_names = { + "N": _("North"), "NE": _("Northeast"), "E": _("East"), "SE": _("Southeast"), + "S": _("South"), "SW": _("Southwest"), "W": _("West"), "NW": _("Northwest"), + } + return render(request, "fireworks_detect/manual_pending_submission.html", { + "pending": pending, + "direction_label": direction_names.get(pending.direction_cardinal) if direction_degrees is not None else "", + }) @never_cache def events_list(request): diff --git a/frontend/src/scripts/burst-listener.js b/frontend/src/scripts/burst-listener.js index 07e9b40..a2bf0fe 100644 --- a/frontend/src/scripts/burst-listener.js +++ b/frontend/src/scripts/burst-listener.js @@ -1,4 +1,5 @@ - const form = document.querySelector("#manual-report-form"); +const form = document.querySelector("#manual-report-form"); +const t = window.BOOMCAST_I18N || {}; export function createBurstListener() { if (!form) return null; @@ -47,12 +48,12 @@ export function createBurstListener() { state = next; if (container) container.dataset.state = next; if (section) section.dataset.state = next; - if (stateLabel) stateLabel.textContent = next === "listening" ? "Listening for the next bang" : next === "tail" ? "Sound detected" : next === "captured" ? "Sound captured" : "Not listening"; + if (stateLabel) stateLabel.textContent = next === "listening" ? (t.listeningNextBang || "Listening for the next bang") : next === "tail" ? (t.soundDetected || "Sound detected") : next === "captured" ? (t.soundCaptured || "Sound captured") : (t.notListening || "Not listening"); start.hidden = next !== "off"; panel.hidden = next === "off"; resume.hidden = discard.hidden = next !== "captured"; - heading.textContent = next === "captured" ? "Sound captured" : next === "tail" ? "Sound detected — finishing clip…" : "Listening for the next sound…"; - detail.textContent = next === "listening" ? "Keeping the most recent ~10 seconds" : next === "captured" ? "Preview the clip or send your report." : ""; + heading.textContent = next === "captured" ? (t.soundCaptured || "Sound captured") : next === "tail" ? (t.soundDetectedFinishing || "Sound detected — finishing clip…") : (t.listeningNextSound || "Listening for the next sound…"); + detail.textContent = next === "listening" ? (t.keepingRecentAudio || "Keeping the most recent ~10 seconds") : next === "captured" ? (t.previewClipOrSend || "Preview the clip or send your report.") : ""; } function wav(samples, rate) { @@ -81,7 +82,7 @@ export function createBurstListener() { start.disabled = true; if (container) container.dataset.state = "starting"; if (section) section.dataset.state = "starting"; - if (stateLabel) stateLabel.textContent = "Starting microphone…"; + if (stateLabel) stateLabel.textContent = t.startingMicrophone || "Starting microphone…"; try { if (!navigator.mediaDevices?.getUserMedia || !window.AudioWorkletNode) throw new Error("Microphone listening is unavailable in this browser or connection."); stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 }, video: false }); @@ -122,8 +123,8 @@ export function createBurstListener() { await end(); if (container) container.dataset.state = "error"; if (section) section.dataset.state = "error"; - if (stateLabel) stateLabel.textContent = "Microphone unavailable"; - error.textContent = cause.name === "NotAllowedError" ? "Microphone permission was denied. Manual reporting is still available." : (cause.message || "Microphone capture failed."); + if (stateLabel) stateLabel.textContent = t.microphoneUnavailable || "Microphone unavailable"; + error.textContent = cause.name === "NotAllowedError" ? (t.microphoneDenied || "Microphone permission was denied. Manual reporting is still available.") : (t.microphoneFailed || "Microphone capture failed."); error.hidden = false; } finally { start.disabled = false; diff --git a/frontend/src/scripts/manual-report.js b/frontend/src/scripts/manual-report.js index c9d20f8..7a945b4 100644 --- a/frontend/src/scripts/manual-report.js +++ b/frontend/src/scripts/manual-report.js @@ -25,7 +25,10 @@ const burstListener = createBurstListener(); const isUsableNumber = (value) => Number.isFinite(value); - const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)]; + const cardinalDirection = (heading) => [ + t.north || "North", t.northeast || "Northeast", t.east || "East", t.southeast || "Southeast", + t.south || "South", t.southwest || "Southwest", t.west || "West", t.northwest || "Northwest", + ][Math.floor(((heading + 22.5) % 360) / 45)]; const displayDegrees = (value) => Number(value.toFixed(1)).toString(); const updateReportTime = () => { if (!reportTime) return; diff --git a/frontend/tests/manual-compass.test.mjs b/frontend/tests/manual-compass.test.mjs index 94f4d5c..2eb24fc 100644 --- a/frontend/tests/manual-compass.test.mjs +++ b/frontend/tests/manual-compass.test.mjs @@ -16,7 +16,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide

- +
`, { url: "https://example.test/" }); const { window } = dom; Object.defineProperty(window, "isSecureContext", { value: true }); @@ -24,8 +24,10 @@ test("compass stays hidden until permission and a heading, then rotates and hide class MockOrientation {} MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; }); window.DeviceOrientationEvent = MockOrientation; - const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)])); - for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation })) { + let submissions = 0; + window.htmx = { ajax: () => { submissions++; } }; + const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent", "htmx", "DOMParser"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)])); + for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation, htmx: window.htmx, DOMParser: window.DOMParser })) { Object.defineProperty(globalThis, key, { configurable: true, writable: true, value }); } try { @@ -51,6 +53,36 @@ test("compass stays hidden until permission and a heading, then rotates and hide assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1"); button.click(); assert.equal(compass.hidden, true); + window.document.querySelector("#manual-increase").click(); + assert.equal(window.document.querySelector("#manual-occurrences").value, "2"); + window.document.querySelector("#manual-decrease").click(); + assert.equal(window.document.querySelector("#manual-occurrences").value, "1"); + + window.document.querySelector("#manual-direction-panel").outerHTML = '

'; + const opened = window.document.querySelector("#manual-direction-panel"); + window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: opened } })); + assert.equal(compass.parentElement.id, "manual-direction-panel"); + window.document.body.dispatchEvent(new window.CustomEvent("htmx:beforeSwap", { detail: { target: opened } })); + assert.equal(compass.parentElement.id, "manual-compass-home"); + opened.outerHTML = '

Not captured

'; + const closed = window.document.querySelector("#manual-direction-panel"); + window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: closed } })); + assert.equal(window.document.querySelector("#manual-direction-summary").textContent, "North · 1°"); + + const submit = window.document.querySelector("#manual-submit"); + const form = window.document.querySelector("#manual-report-form"); + submit.click(); + submit.click(); + assert.equal(submissions, 1); + assert.equal(submit.disabled, true); + window.document.querySelector("#manual-submission").outerHTML = '
Received
'; + window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 200 } } })); + assert.equal(submit.disabled, false); + submit.click(); + assert.equal(submissions, 2); + window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 400, responseText: '
Try again
' } } })); + assert.equal(window.document.querySelector("#manual-submission").dataset.result, "error"); + assert.equal(submit.disabled, false); } finally { for (const [key, descriptor] of Object.entries(previous)) { if (descriptor === undefined) delete globalThis[key]; diff --git a/locale/nl/LC_MESSAGES/django.mo b/locale/nl/LC_MESSAGES/django.mo index 6b08bad..eaba9c5 100644 Binary files a/locale/nl/LC_MESSAGES/django.mo and b/locale/nl/LC_MESSAGES/django.mo differ diff --git a/locale/nl/LC_MESSAGES/django.po b/locale/nl/LC_MESSAGES/django.po index da4f931..ac5e129 100644 --- a/locale/nl/LC_MESSAGES/django.po +++ b/locale/nl/LC_MESSAGES/django.po @@ -1286,3 +1286,117 @@ msgstr "De server verwerkt momenteel alleen audio-opnamen. Kies een audiobestand msgid "Local checking was unavailable. BoomCast will use normal server processing." msgstr "Lokale controle was niet beschikbaar. BoomCast gebruikt de normale verwerking op de server." + +msgid "Quick report" +msgstr "Snelle melding" + +msgid "Did you hear a bang? Report what you heard in a few taps." +msgstr "Heb je een knal gehoord? Meld in een paar tikken wat je hoorde." + +msgid "Now" +msgstr "Nu" + +msgid "How many times did you hear it?" +msgstr "Hoe vaak hoorde je het?" + +msgid "Decrease occurrences" +msgstr "Aantal verlagen" + +msgid "Increase occurrences" +msgstr "Aantal verhogen" + +msgid "I heard fireworks" +msgstr "Ik hoorde vuurwerk" + +msgid "Automatic detection" +msgstr "Automatische detectie" + +msgid "Not listening" +msgstr "Luistert niet" + +msgid "Start listening" +msgstr "Start luisteren" + +msgid "Close direction capture" +msgstr "Richtingmeting sluiten" + +msgid "Start measuring direction" +msgstr "Richting meten" + +msgid "Not captured" +msgstr "Niet vastgelegd" + +msgid "Report received!" +msgstr "Melding ontvangen!" + +msgid "Thank you. Your report helps map fireworks nearby." +msgstr "Bedankt voor je bijdrage. Je melding helpt om vuurwerk in de buurt in kaart te brengen." + +msgid "Stop measuring direction" +msgstr "Stop richting meten" + +msgid "Measure again" +msgstr "Opnieuw meten" + +msgid "Sending…" +msgstr "Versturen…" + +msgid "Could not send the report. Please try again." +msgstr "De melding kon niet worden verzonden. Probeer het opnieuw." + +msgid "North" +msgstr "Noord" + +msgid "Northeast" +msgstr "Noordoost" + +msgid "East" +msgstr "Oost" + +msgid "Southeast" +msgstr "Zuidoost" + +msgid "South" +msgstr "Zuid" + +msgid "Southwest" +msgstr "Zuidwest" + +msgid "West" +msgstr "West" + +msgid "Northwest" +msgstr "Noordwest" + +msgid "Listening for the next bang" +msgstr "Luistert naar de volgende knal" + +msgid "Sound detected" +msgstr "Geluid gedetecteerd" + +msgid "Sound captured" +msgstr "Geluid vastgelegd" + +msgid "Sound detected — finishing clip…" +msgstr "Geluid gedetecteerd — opname afronden…" + +msgid "Listening for the next sound…" +msgstr "Luistert naar het volgende geluid…" + +msgid "Keeping the most recent ~10 seconds" +msgstr "Bewaart de laatste ~10 seconden" + +msgid "Preview the clip or send your report." +msgstr "Luister de opname terug of dien je melding in." + +msgid "Starting microphone…" +msgstr "Microfoon starten…" + +msgid "Microphone unavailable" +msgstr "Microfoon niet beschikbaar" + +msgid "Microphone permission was denied. Manual reporting is still available." +msgstr "Toegang tot de microfoon is geweigerd. Je kunt nog steeds handmatig melden." + +msgid "Microphone capture failed." +msgstr "Opnemen met de microfoon is mislukt." diff --git a/members/templates/members/user_settings.html b/members/templates/members/user_settings.html index 5a9b2ca..c3aac49 100644 --- a/members/templates/members/user_settings.html +++ b/members/templates/members/user_settings.html @@ -7,7 +7,8 @@ {% trans "Settings · Sound Signal" %} {% vite_asset "frontend/src/entries/settings.js" %} -{% include "js_translations.html" %} + {% include "js_translations.html" %} +
{% include "fireworks_detect/includes/navigation.html" %} diff --git a/templates/js_translations.html b/templates/js_translations.html index 57085df..1d87918 100644 --- a/templates/js_translations.html +++ b/templates/js_translations.html @@ -23,6 +23,26 @@ window.BOOMCAST_I18N = { requestingLocation: "{% trans 'Requesting your optional location…' as value %}{{ value|escapejs }}", sendingReport: "{% trans 'Sending…' as value %}{{ value|escapejs }}", reportFailed: "{% trans 'Could not send the report. Please try again.' as value %}{{ value|escapejs }}", + north: "{% trans 'North' as value %}{{ value|escapejs }}", + northeast: "{% trans 'Northeast' as value %}{{ value|escapejs }}", + east: "{% trans 'East' as value %}{{ value|escapejs }}", + southeast: "{% trans 'Southeast' as value %}{{ value|escapejs }}", + south: "{% trans 'South' as value %}{{ value|escapejs }}", + southwest: "{% trans 'Southwest' as value %}{{ value|escapejs }}", + west: "{% trans 'West' as value %}{{ value|escapejs }}", + northwest: "{% trans 'Northwest' as value %}{{ value|escapejs }}", + listeningNextBang: "{% trans 'Listening for the next bang' as value %}{{ value|escapejs }}", + soundDetected: "{% trans 'Sound detected' as value %}{{ value|escapejs }}", + soundCaptured: "{% trans 'Sound captured' as value %}{{ value|escapejs }}", + notListening: "{% trans 'Not listening' as value %}{{ value|escapejs }}", + soundDetectedFinishing: "{% trans 'Sound detected — finishing clip…' as value %}{{ value|escapejs }}", + listeningNextSound: "{% trans 'Listening for the next sound…' as value %}{{ value|escapejs }}", + keepingRecentAudio: "{% trans 'Keeping the most recent ~10 seconds' as value %}{{ value|escapejs }}", + previewClipOrSend: "{% trans 'Preview the clip or send your report.' as value %}{{ value|escapejs }}", + startingMicrophone: "{% trans 'Starting microphone…' as value %}{{ value|escapejs }}", + microphoneUnavailable: "{% trans 'Microphone unavailable' as value %}{{ value|escapejs }}", + microphoneDenied: "{% trans 'Microphone permission was denied. Manual reporting is still available.' as value %}{{ value|escapejs }}", + microphoneFailed: "{% trans 'Microphone capture failed.' as value %}{{ value|escapejs }}", mapCompass: "{% trans 'Map compass: north is up' as value %}{{ value|escapejs }}", reports: "{% trans 'reports' as value %}{{ value|escapejs }}", occurrences: "{% trans 'occurrences' as value %}{{ value|escapejs }}",