Skip to content

Commit

Permalink
feat: localize error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcabo committed Oct 7, 2024
1 parent ee0be3b commit 59093f1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/components/chat/Chat.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion app/components/sidebar/Menu.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function Menu() {
}
})
.catch((error) => {
toast.error('Failed to delete conversation');
toast.error(t('toast.error.failedToDeleteConversation'));
logger.error(error);
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/workbench/Workbench.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}, []);

Expand Down
5 changes: 3 additions & 2 deletions app/lib/persistence/useChatHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions public/locales/ca/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
8 changes: 8 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
10 changes: 9 additions & 1 deletion public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}

0 comments on commit 59093f1

Please sign in to comment.