fix: translate months in journey timeline (#815)

formatDate() in both JourneyDetailPage and JourneyPublicPage passed
undefined/'en' as the locale to toLocaleDateString, so weekday/month
names always followed the browser's language instead of the app's
selected UI language. Thread the selected locale through from
useTranslation() in both pages.

Public view still falls back to 'en' when no settings locale is
available (shared links can be opened by anyone).
This commit is contained in:
Maurice
2026-04-21 22:16:43 +02:00
parent 906d8821a4
commit 32f431e879
2 changed files with 13 additions and 11 deletions
+9 -7
View File
@@ -67,11 +67,13 @@ function groupByDate(entries: JourneyEntry[]): Map<string, JourneyEntry[]> {
return groups return groups
} }
function formatDate(d: string): { weekday: string; month: string; day: number } { function formatDate(d: string, locale?: string): { weekday: string; month: string; day: number } {
const date = new Date(d + 'T00:00:00') const date = new Date(d + 'T00:00:00')
// Pass the app's selected locale so weekday/month follow the UI language
// instead of the browser's navigator.language.
return { return {
weekday: date.toLocaleDateString(undefined, { weekday: 'long' }), weekday: date.toLocaleDateString(locale, { weekday: 'long' }),
month: date.toLocaleDateString(undefined, { month: 'long' }), month: date.toLocaleDateString(locale, { month: 'long' }),
day: date.getDate(), day: date.getDate(),
} }
} }
@@ -84,7 +86,7 @@ export default function JourneyDetailPage() {
const { id } = useParams() const { id } = useParams()
const navigate = useNavigate() const navigate = useNavigate()
const toast = useToast() const toast = useToast()
const { t } = useTranslation() const { t, locale } = useTranslation()
const { current, loading, notFound, loadJourney, updateEntry, deleteEntry, reorderEntries, uploadPhotos, deletePhoto } = useJourneyStore() const { current, loading, notFound, loadJourney, updateEntry, deleteEntry, reorderEntries, uploadPhotos, deletePhoto } = useJourneyStore()
const mapRef = useRef<JourneyMapHandle>(null) const mapRef = useRef<JourneyMapHandle>(null)
const fullMapRef = useRef<JourneyMapHandle>(null) const fullMapRef = useRef<JourneyMapHandle>(null)
@@ -575,7 +577,7 @@ export default function JourneyDetailPage() {
{sortedDates.map((date, dayIdx) => { {sortedDates.map((date, dayIdx) => {
const entries = dayGroups.get(date)! const entries = dayGroups.get(date)!
const fd = formatDate(date) const fd = formatDate(date, locale)
const locations = [...new Set(entries.map(e => e.location_name).filter(Boolean))] const locations = [...new Set(entries.map(e => e.location_name).filter(Boolean))]
return ( return (
@@ -816,7 +818,7 @@ function MapView({ entries, mapEntries, sortedDates, activeLocationId, fullMapRe
fullMapRef: React.RefObject<JourneyMapHandle | null> fullMapRef: React.RefObject<JourneyMapHandle | null>
onLocationClick: (id: string) => void onLocationClick: (id: string) => void
}) { }) {
const { t } = useTranslation() const { t, locale } = useTranslation()
// group map entries by date // group map entries by date
const byDate = new Map<string, { entry: JourneyEntry; globalIdx: number }[]>() const byDate = new Map<string, { entry: JourneyEntry; globalIdx: number }[]>()
mapEntries.forEach((e, i) => { mapEntries.forEach((e, i) => {
@@ -872,7 +874,7 @@ function MapView({ entries, mapEntries, sortedDates, activeLocationId, fullMapRe
<div className="px-5 pb-5"> <div className="px-5 pb-5">
{dates.map((date, dayIdx) => { {dates.map((date, dayIdx) => {
const items = byDate.get(date)! const items = byDate.get(date)!
const fd = formatDate(date) const fd = formatDate(date, locale)
return ( return (
<div key={date}> <div key={date}>
+4 -4
View File
@@ -40,11 +40,11 @@ function photoUrl(p: PublicPhoto, shareToken: string, kind: 'thumbnail' | 'origi
return `/api/public/journey/${shareToken}/photos/${p.photo_id}/${kind}` return `/api/public/journey/${shareToken}/photos/${p.photo_id}/${kind}`
} }
function formatDate(d: string): { weekday: string; month: string; day: number } { function formatDate(d: string, locale?: string): { weekday: string; month: string; day: number } {
const date = new Date(d + 'T00:00:00') const date = new Date(d + 'T00:00:00')
return { return {
weekday: date.toLocaleDateString('en', { weekday: 'long' }), weekday: date.toLocaleDateString(locale || 'en', { weekday: 'long' }),
month: date.toLocaleDateString('en', { month: 'long' }), month: date.toLocaleDateString(locale || 'en', { month: 'long' }),
day: date.getDate(), day: date.getDate(),
} }
} }
@@ -233,7 +233,7 @@ export default function JourneyPublicPage() {
<div className="flex flex-col gap-6"> <div className="flex flex-col gap-6">
{sortedDates.map(date => { {sortedDates.map(date => {
const dayEntries = groupedEntries.get(date)! const dayEntries = groupedEntries.get(date)!
const fd = formatDate(date) const fd = formatDate(date, locale)
return ( return (
<div key={date}> <div key={date}>
<div className="flex items-center gap-3 mb-4"> <div className="flex items-center gap-3 mb-4">