feat: localize error messages

This commit is contained in:
Yoel Cabo 2024-10-07 10:16:56 +02:00
parent ee0be3b605
commit 59093f1ad6
7 changed files with 34 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import { fileModificationsToHTML } from '~/utils/diff';
import { cubicEasingFn } from '~/utils/easings';
import { createScopedLogger, renderLogger } from '~/utils/logger';
import { BaseChat } from './BaseChat';
import { useTranslation } from 'react-i18next';
const toastAnimation = cssTransition({
enter: 'animated fadeInRight',
@ -75,11 +76,13 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
const [animationScope, animate] = useAnimate();
const { t } = useTranslation();
const { messages, isLoading, input, handleInputChange, setInput, stop, append } = useChat({
api: '/api/chat',
onError: (error) => {
logger.error('Request failed\n\n', error);
toast.error('There was an error processing your request');
toast.error(t('toast.error.generic'));
},
onFinish: () => {
logger.debug('Finished streaming');

View File

@ -64,7 +64,7 @@ export function Menu() {
}
})
.catch((error) => {
toast.error('Failed to delete conversation');
toast.error(t('toast.error.failedToDeleteConversation'));
logger.error(error);
});
}

View File

@ -92,7 +92,7 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
const onFileSave = useCallback(() => {
workbenchStore.saveCurrentDocument().catch(() => {
toast.error('Failed to update file content');
toast.error(t('toast.error.failedToUpdateFileContent'));
});
}, []);

View File

@ -5,7 +5,7 @@ import type { Message } from 'ai';
import { toast } from 'react-toastify';
import { workbenchStore } from '~/lib/stores/workbench';
import { getMessages, getNextId, getUrlId, openDatabase, setMessages } from './db';
import { useTranslation } from 'react-i18next';
export interface ChatHistoryItem {
id: string;
urlId?: string;
@ -28,13 +28,14 @@ export function useChatHistory() {
const [initialMessages, setInitialMessages] = useState<Message[]>([]);
const [ready, setReady] = useState<boolean>(false);
const [urlId, setUrlId] = useState<string | undefined>();
const { t } = useTranslation();
useEffect(() => {
if (!db) {
setReady(true);
if (persistenceEnabled) {
toast.error(`Chat persistence is unavailable`);
toast.error(t('toast.error.chatPersistenceUnavailable'));
}
return;

View File

@ -47,5 +47,13 @@
"spaceInvaders": "Crea un joc d'Space Invaders",
"centerDiv": "Com centro un div?"
}
},
"toast": {
"error": {
"generic": "S'ha produït un error",
"failedToDeleteConversation": "No s'ha pogut eliminar la conversa",
"failedToUpdateFileContent": "No s'ha pogut actualitzar el contingut del fitxer",
"chatPersistenceUnavailable": "La persistència del xat no està disponible"
}
}
}

View File

@ -47,5 +47,13 @@
"spaceInvaders": "Make a space invaders game",
"centerDiv": "How do I center a div?"
}
},
"toast": {
"error": {
"generic": "There was an error processing your request",
"failedToDeleteConversation": "Failed to delete conversation",
"failedToUpdateFileContent": "Failed to update file content",
"chatPersistenceUnavailable": "Chat persistence is unavailable"
}
}
}

View File

@ -46,5 +46,13 @@
"spaceInvaders": "Crea un juego como Space Invaders",
"centerDiv": "¿Cómo centro un div?"
}
},
"toast": {
"error": {
"generic": "Se produjo un error",
"failedToDeleteConversation": "No se pudo eliminar la conversación",
"failedToUpdateFileContent": "No se pudo actualizar el contenido del archivo",
"chatPersistenceUnavailable": "La persistencia del chat no está disponible"
}
}
}
}