fix: use i18n locale for timestamp formatting instead of hardcoded fr-FR

This commit is contained in:
Nicolas Varrot
2026-02-11 14:31:32 +00:00
parent 2d3ee47854
commit 88c393ed50
2 changed files with 12 additions and 3 deletions

View File

@@ -6,12 +6,16 @@ import type { ChatMessage as ChatMessageType, MessageBlock } from '../types';
import { ThinkingBlock } from './ThinkingBlock'; import { ThinkingBlock } from './ThinkingBlock';
import { ToolCall } from './ToolCall'; import { ToolCall } from './ToolCall';
import { Bot, User, Wrench } from 'lucide-react'; import { Bot, User, Wrench } from 'lucide-react';
import { t, locale } from '../lib/i18n';
// ChevronDown, ChevronRight, Wrench still used by InternalOnlyMessage // 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 { function formatTimestamp(ts: number): string {
const date = new Date(ts); const date = new Date(ts);
const now = new Date(); 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 isToday = date.toDateString() === now.toDateString();
const yesterday = new Date(now); const yesterday = new Date(now);
@@ -19,8 +23,8 @@ function formatTimestamp(ts: number): string {
const isYesterday = date.toDateString() === yesterday.toDateString(); const isYesterday = date.toDateString() === yesterday.toDateString();
if (isToday) return time; if (isToday) return time;
if (isYesterday) return `Hier ${time}`; if (isYesterday) return `${t('time.yesterday')} ${time}`;
return `${date.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' })} ${time}`; return `${date.toLocaleDateString(bcp47Locale, { day: 'numeric', month: 'short' })} ${time}`;
} }
/** Guess a language hint from content patterns */ /** Guess a language hint from content patterns */

View File

@@ -43,6 +43,9 @@ const en = {
// Tool call // Tool call
'tool.result': 'Result', 'tool.result': 'Result',
// Timestamps
'time.yesterday': 'Yesterday',
} as const; } as const;
const fr: Record<keyof typeof en, string> = { const fr: Record<keyof typeof en, string> = {
@@ -78,6 +81,8 @@ const fr: Record<keyof typeof en, string> = {
'thinking.label': 'Réflexion', 'thinking.label': 'Réflexion',
'tool.result': 'Résultat', 'tool.result': 'Résultat',
'time.yesterday': 'Hier',
}; };
const messages: Record<string, Record<string, string>> = { en, fr }; const messages: Record<string, Record<string, string>> = { en, fr };