fix: enforce dd/mm/yyyy, 24h time, and locale-aware location search
- Replace all 'en-US' and undefined locales with 'en-GB' in date formatting across 15+ frontend files (dateUtils.ts, cards, routes, Luxon calls) to consistently output day-first dates and 24h times - Set hour12: false in all Intl.DateTimeFormat and toLocaleDateString calls that previously used 12h format - Pass user's svelte-i18n locale as &lang= query param from LocationSearchMap and LocationQuickStart to the reverse-geocode API - Extract lang param in reverse_geocode_view and forward to both search_osm and search_google - Add Accept-Language header to Nominatim requests so searches return results in the user's language (e.g. Prague not Praha) - Add languageCode field to Google Places API payload for same effect
This commit is contained in:
@@ -42,12 +42,13 @@
|
||||
}
|
||||
|
||||
function formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
return new Date(dateString).toLocaleDateString('en-GB', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
minute: '2-digit',
|
||||
hour12: false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
<div class="flex items-center gap-2">
|
||||
<Calendar class="w-4 h-4 text-primary" />
|
||||
<span>
|
||||
{new Date(checklist.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}
|
||||
{new Date(checklist.date).toLocaleDateString('en-GB', { timeZone: 'UTC' })}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -440,7 +440,7 @@
|
||||
{#if checklist.date && checklist.date !== ''}
|
||||
<div class="flex items-center gap-1">
|
||||
<Calendar class="w-4 h-4 text-primary" />
|
||||
<span>{new Date(checklist.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</span>
|
||||
<span>{new Date(checklist.date).toLocaleDateString('en-GB', { timeZone: 'UTC' })}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -285,12 +285,12 @@
|
||||
<!-- Date Range (if exists) -->
|
||||
{#if collection.start_date && collection.end_date}
|
||||
<div class="text-xs text-base-content/60">
|
||||
{new Date(collection.start_date).toLocaleDateString(undefined, {
|
||||
{new Date(collection.start_date).toLocaleDateString('en-GB', {
|
||||
timeZone: 'UTC',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric'
|
||||
})} – {new Date(collection.end_date).toLocaleDateString(undefined, {
|
||||
})} – {new Date(collection.end_date).toLocaleDateString('en-GB', {
|
||||
timeZone: 'UTC',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
|
||||
@@ -120,8 +120,8 @@
|
||||
{#if note.date && note.date !== ''}
|
||||
<div class="flex items-center gap-2">
|
||||
<Calendar class="w-4 h-4 text-primary" />
|
||||
<span>{new Date(note.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</span
|
||||
>
|
||||
<span>{new Date(note.date).toLocaleDateString('en-GB', { timeZone: 'UTC' })}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if note.links && note.links?.length > 0}
|
||||
@@ -319,7 +319,7 @@
|
||||
{#if note.date && note.date !== ''}
|
||||
<div class="flex items-center gap-1">
|
||||
<Calendar class="w-4 h-4 text-primary" />
|
||||
<span>{new Date(note.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</span>
|
||||
<span>{new Date(note.date).toLocaleDateString('en-GB', { timeZone: 'UTC' })}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
}
|
||||
|
||||
function formatDate(date: string | number | Date) {
|
||||
return new Date(date).toLocaleDateString();
|
||||
return new Date(date).toLocaleDateString('en-GB');
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
<Calendar class="w-4 h-4 text-primary" />
|
||||
<span>
|
||||
{user.date_joined
|
||||
? `${$t('adventures.joined')} ` + new Date(user.date_joined).toLocaleDateString()
|
||||
? `${$t('adventures.joined')} ` + new Date(user.date_joined).toLocaleDateString('en-GB')
|
||||
: ''}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
*/
|
||||
function formatDate(dateString: string | number | Date) {
|
||||
if (!dateString) return '';
|
||||
return new Date(dateString).toLocaleDateString();
|
||||
return new Date(dateString).toLocaleDateString('en-GB');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -264,7 +264,7 @@
|
||||
|
||||
$: windowLabel =
|
||||
tripStart && tripEnd
|
||||
? `${tripStart.toLocaleString(DateTime.DATE_MED)} - ${tripEnd.toLocaleString(DateTime.DATE_MED)}`
|
||||
? `${tripStart.toLocaleString(DateTime.DATE_MED, { locale: 'en-GB' })} - ${tripEnd.toLocaleString(DateTime.DATE_MED, { locale: 'en-GB' })}`
|
||||
: null;
|
||||
|
||||
function normalizeTransportType(type?: string | null): string {
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
}
|
||||
|
||||
function formatDate(dateString: string | number | Date) {
|
||||
return new Date(dateString).toLocaleDateString();
|
||||
return new Date(dateString).toLocaleDateString('en-GB');
|
||||
}
|
||||
|
||||
async function fetchWandererTrails(filter = '') {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import { MapLibre, Marker, MapEvents } from 'svelte-maplibre';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { locale, t } from 'svelte-i18n';
|
||||
import { getBasemapUrl } from '$lib';
|
||||
|
||||
// Icons
|
||||
@@ -44,7 +44,7 @@
|
||||
isSearching = true;
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(query)}`
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(query)}&lang=${encodeURIComponent($locale ?? 'en')}`
|
||||
);
|
||||
const results = await response.json();
|
||||
|
||||
@@ -105,7 +105,9 @@
|
||||
|
||||
try {
|
||||
// Using a coordinate-based search query for reverse geocoding
|
||||
const response = await fetch(`/api/reverse-geocode/search/?query=${lat},${lng}`);
|
||||
const response = await fetch(
|
||||
`/api/reverse-geocode/search/?query=${lat},${lng}&lang=${encodeURIComponent($locale ?? 'en')}`
|
||||
);
|
||||
const results = await response.json();
|
||||
|
||||
if (results && results.length > 0) {
|
||||
|
||||
@@ -147,17 +147,17 @@
|
||||
// Helper functions
|
||||
function formatDateInTimezone(utcDate: string, timezone: string): string {
|
||||
try {
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
return new Intl.DateTimeFormat('en-GB', {
|
||||
timeZone: timezone,
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: true
|
||||
hour12: false
|
||||
}).format(new Date(utcDate));
|
||||
} catch {
|
||||
return new Date(utcDate).toLocaleString();
|
||||
return new Date(utcDate).toLocaleString('en-GB');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,8 +957,8 @@
|
||||
{formatDateInTimezone(visit.start_date, visit.timezone)}
|
||||
– {formatDateInTimezone(visit.end_date, visit.timezone)}
|
||||
{:else}
|
||||
{new Date(visit.start_date).toLocaleString()}
|
||||
– {new Date(visit.end_date).toLocaleString()}
|
||||
{new Date(visit.start_date).toLocaleString('en-GB')}
|
||||
– {new Date(visit.end_date).toLocaleString('en-GB')}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { MapLibre, Marker, MapEvents } from 'svelte-maplibre';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { locale, t } from 'svelte-i18n';
|
||||
import { getBasemapUrl } from '$lib';
|
||||
|
||||
import SearchIcon from '~icons/mdi/magnify';
|
||||
@@ -200,7 +200,7 @@
|
||||
try {
|
||||
const searchTerm = airportMode ? `${query} Airport` : query;
|
||||
const response = await fetch(
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}`
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}&lang=${encodeURIComponent($locale ?? 'en')}`
|
||||
);
|
||||
const results = await response.json();
|
||||
|
||||
@@ -233,7 +233,7 @@
|
||||
try {
|
||||
const searchTerm = airportMode ? `${query} Airport` : query;
|
||||
const response = await fetch(
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}`
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}&lang=${encodeURIComponent($locale ?? 'en')}`
|
||||
);
|
||||
const results = await response.json();
|
||||
|
||||
@@ -266,7 +266,7 @@
|
||||
try {
|
||||
const searchTerm = airportMode ? `${query} Airport` : query;
|
||||
const response = await fetch(
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}`
|
||||
`/api/reverse-geocode/search/?query=${encodeURIComponent(searchTerm)}&lang=${encodeURIComponent($locale ?? 'en')}`
|
||||
);
|
||||
const results = await response.json();
|
||||
|
||||
|
||||
@@ -92,17 +92,17 @@ export function validateDateRange(
|
||||
export function formatDateInTimezone(utcDate: string, timezone: string | null): string {
|
||||
if (!utcDate) return '';
|
||||
try {
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
return new Intl.DateTimeFormat('en-GB', {
|
||||
timeZone: timezone || undefined,
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: true
|
||||
hour12: false
|
||||
}).format(new Date(utcDate));
|
||||
} catch {
|
||||
return new Date(utcDate).toLocaleString();
|
||||
return new Date(utcDate).toLocaleString('en-GB');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export function formatAllDayDate(dateString: string): string {
|
||||
if (!dateString) return '';
|
||||
const datePart = dateString.split('T')[0];
|
||||
const dateWithMidday = `${datePart}T12:00:00`;
|
||||
return new Intl.DateTimeFormat('en-US', {
|
||||
return new Intl.DateTimeFormat('en-GB', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
|
||||
Reference in New Issue
Block a user