feat(desktop): add i18n infrastructure with react-intl (#8105)

This commit is contained in:
jh-block
2026-03-27 19:39:50 +01:00
committed by GitHub
parent d596113e72
commit a6765fbcd9
172 changed files with 13793 additions and 2054 deletions
+29 -6
View File
@@ -6,6 +6,7 @@ import React, {
useRef,
useState,
} from 'react';
import { defineMessages, useIntl } from '../i18n';
import { useLocation, useNavigate } from 'react-router-dom';
import { SearchView } from './conversation/SearchView';
import LoadingGoose from './LoadingGoose';
@@ -40,7 +41,28 @@ import { useAutoSubmit } from '../hooks/useAutoSubmit';
import { Goose } from './icons';
import EnvironmentBadge from './GooseSidebar/EnvironmentBadge';
const i18n = defineMessages({
failedToLoadSession: {
id: 'baseChat.failedToLoadSession',
defaultMessage: 'Failed to Load Session',
},
goHome: {
id: 'baseChat.goHome',
defaultMessage: 'Go home',
},
noSession: {
id: 'baseChat.noSession',
defaultMessage: 'No Session',
},
recipeCreatedTitle: {
id: 'baseChat.recipeCreatedTitle',
defaultMessage: 'Recipe created successfully!',
},
recipeCreatedMessage: {
id: 'baseChat.recipeCreatedMessage',
defaultMessage: '"{title}" has been saved and is ready to use.',
},
});
interface BaseChatProps {
setChat: (chat: ChatType) => void;
@@ -66,6 +88,7 @@ export default function BaseChat({
initialMessage,
isActiveSession,
}: BaseChatProps) {
const intl = useIntl();
const location = useLocation();
const navigate = useNavigate();
const scrollRef = useRef<ScrollAreaHandle>(null);
@@ -298,8 +321,8 @@ export default function BaseChat({
const handleRecipeCreated = (recipe: Recipe) => {
toastSuccess({
title: 'Recipe created successfully!',
msg: `"${recipe.title}" has been saved and is ready to use.`,
title: intl.formatMessage(i18n.recipeCreatedTitle),
msg: intl.formatMessage(i18n.recipeCreatedMessage, { title: recipe.title }),
});
};
@@ -310,7 +333,7 @@ export default function BaseChat({
messages,
recipe,
sessionId,
name: session?.name || 'No Session',
name: session?.name || intl.formatMessage(i18n.noSession),
};
const lastSetNameRef = useRef<string>('');
@@ -352,7 +375,7 @@ export default function BaseChat({
<div className="flex-1 bg-background-primary rounded-b-2xl flex items-center justify-center">
<div className="flex flex-col items-center justify-center p-8">
<div className="text-red-700 dark:text-red-300 bg-red-400/50 p-4 rounded-lg mb-4 max-w-md">
<h3 className="font-semibold mb-2">Failed to Load Session</h3>
<h3 className="font-semibold mb-2">{intl.formatMessage(i18n.failedToLoadSession)}</h3>
<p className="text-sm">{sessionLoadError}</p>
</div>
<button
@@ -361,7 +384,7 @@ export default function BaseChat({
}}
className="px-4 py-2 text-center cursor-pointer text-text-primary border border-border-primary hover:bg-background-secondary rounded-lg transition-all duration-150"
>
Go home
{intl.formatMessage(i18n.goHome)}
</button>
</div>
</div>