From 88c393ed50969829cf3a8ed192f7733fdc02cb11 Mon Sep 17 00:00:00 2001 From: Nicolas Varrot Date: Wed, 11 Feb 2026 14:31:32 +0000 Subject: [PATCH] fix: use i18n locale for timestamp formatting instead of hardcoded fr-FR --- src/components/ChatMessage.tsx | 10 +++++++--- src/lib/i18n.ts | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/ChatMessage.tsx b/src/components/ChatMessage.tsx index 769c39a..0b1f447 100644 --- a/src/components/ChatMessage.tsx +++ b/src/components/ChatMessage.tsx @@ -6,12 +6,16 @@ import type { ChatMessage as ChatMessageType, MessageBlock } from '../types'; import { ThinkingBlock } from './ThinkingBlock'; import { ToolCall } from './ToolCall'; import { Bot, User, Wrench } from 'lucide-react'; +import { t, locale } from '../lib/i18n'; // ChevronDown, ChevronRight, Wrench still used by InternalOnlyMessage +/** Map i18n locale code to BCP-47 locale for Intl formatting */ +const bcp47Locale = locale === 'fr' ? 'fr-FR' : 'en-US'; + function formatTimestamp(ts: number): string { const date = new Date(ts); const now = new Date(); - const time = date.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' }); + const time = date.toLocaleTimeString(bcp47Locale, { hour: '2-digit', minute: '2-digit' }); const isToday = date.toDateString() === now.toDateString(); const yesterday = new Date(now); @@ -19,8 +23,8 @@ function formatTimestamp(ts: number): string { const isYesterday = date.toDateString() === yesterday.toDateString(); if (isToday) return time; - if (isYesterday) return `Hier ${time}`; - return `${date.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' })} ${time}`; + if (isYesterday) return `${t('time.yesterday')} ${time}`; + return `${date.toLocaleDateString(bcp47Locale, { day: 'numeric', month: 'short' })} ${time}`; } /** Guess a language hint from content patterns */ diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 9c47b13..2ffc0d0 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -43,6 +43,9 @@ const en = { // Tool call 'tool.result': 'Result', + + // Timestamps + 'time.yesterday': 'Yesterday', } as const; const fr: Record = { @@ -78,6 +81,8 @@ const fr: Record = { 'thinking.label': 'Réflexion', 'tool.result': 'Résultat', + + 'time.yesterday': 'Hier', }; const messages: Record> = { en, fr };