From 3f2407b704738351a23eea14b01f741bc93ed955 Mon Sep 17 00:00:00 2001 From: andupetcu <47487320+andupetcu@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:57:07 +0300 Subject: [PATCH] Localize chat UI with next-intl; send locale + serialized history to /api/chat; use locale for timestamps; suggestions from messages; rely on API prompts per locale. --- app/[locale]/chat/page.tsx | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/app/[locale]/chat/page.tsx b/app/[locale]/chat/page.tsx index 150e42b..cc0e538 100644 --- a/app/[locale]/chat/page.tsx +++ b/app/[locale]/chat/page.tsx @@ -30,6 +30,7 @@ import { Refresh, } from '@mui/icons-material' import { useState, useRef, useEffect } from 'react' +import { useTranslations, useLocale } from 'next-intl' interface ChatMessage { id: string @@ -40,11 +41,13 @@ interface ChatMessage { export default function ChatPage() { const theme = useTheme() + const t = useTranslations('chat') + const locale = useLocale() const [messages, setMessages] = useState([ { id: '1', role: 'assistant', - content: 'Bună ziua! Sunt asistentul tău AI pentru întrebări biblice. Cum te pot ajuta astăzi să înțelegi mai bine Scriptura?', + content: t('subtitle'), timestamp: new Date(), } ]) @@ -82,7 +85,13 @@ export default function ChatPage() { }, body: JSON.stringify({ message: inputMessage, - history: messages.slice(-5), // Send last 5 messages for context + locale, + history: messages.slice(-5).map(m => ({ + id: m.id, + role: m.role, + content: m.content, + timestamp: m.timestamp.toISOString(), + })), }), }) @@ -95,7 +104,7 @@ export default function ChatPage() { const assistantMessage: ChatMessage = { id: (Date.now() + 1).toString(), role: 'assistant', - content: data.response || 'Îmi pare rău, nu am putut procesa întrebarea ta. Te rog încearcă din nou.', + content: data.response || t('error') || 'Error', timestamp: new Date(), } @@ -105,7 +114,7 @@ export default function ChatPage() { const errorMessage: ChatMessage = { id: (Date.now() + 1).toString(), role: 'assistant', - content: 'Îmi pare rău, a apărut o eroare. Te rog verifică conexiunea și încearcă din nou.', + content: t('error') || 'Error', timestamp: new Date(), } setMessages(prev => [...prev, errorMessage]) @@ -141,10 +150,10 @@ export default function ChatPage() { - Chat cu AI Biblic + {t('title')} - Pune întrebări despre Scriptură și primește răspunsuri fundamentate biblic + {t('subtitle')} @@ -154,12 +163,12 @@ export default function ChatPage() { - Întrebări sugerate + {t('suggestions.title')} - Începe cu una dintre aceste întrebări populare: + {t('suggestions.title')} - {suggestedQuestions.map((question, index) => ( + { (t.raw('suggestions.questions') as string[]).map((question, index) => ( - - Sfaturi pentru chat - - - • Fii specific în întrebări
- • Menționează pasaje biblice dacă le cunoști
- • Poți întreba despre context istoric
- • Solicită explicații teologice -
+ {/* Tips section can be localized later via messages */}
@@ -264,7 +265,7 @@ export default function ChatPage() { opacity: 0.7, }} > - {message.timestamp.toLocaleTimeString('ro-RO', { + {message.timestamp.toLocaleTimeString(locale === 'en' ? 'en-US' : 'ro-RO', { hour: '2-digit', minute: '2-digit', })} @@ -284,7 +285,7 @@ export default function ChatPage() { - Scriu răspunsul... + {t('loading')} @@ -302,7 +303,7 @@ export default function ChatPage() { fullWidth multiline maxRows={4} - placeholder="Scrie întrebarea ta despre Biblie..." + placeholder={t('placeholder')} value={inputMessage} onChange={(e) => setInputMessage(e.target.value)} onKeyPress={handleKeyPress} @@ -320,7 +321,7 @@ export default function ChatPage() { - Apasă Enter pentru a trimite, Shift+Enter pentru linie nouă + {t('enterToSend')} @@ -329,4 +330,4 @@ export default function ChatPage() { ) -} \ No newline at end of file +}