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 -