前端添加中英文切换
This commit is contained in:
+20
-18
@@ -12,10 +12,12 @@ import Footer from './components/Footer';
|
||||
import LoginPage from './components/LoginPage';
|
||||
import SignUpPage from './components/SignUpPage';
|
||||
import ToastProvider, { toast } from './components/Toast';
|
||||
import { useLanguage } from './i18n/LanguageContext';
|
||||
|
||||
type View = 'landing' | 'input' | 'loading' | 'planner' | 'error' | 'login' | 'signup' | 'history';
|
||||
|
||||
const App: React.FC = () => {
|
||||
const { t } = useLanguage();
|
||||
const [view, setView] = useState<View>('landing');
|
||||
const [currentPlan, setCurrentPlan] = useState<Plan | null>(null);
|
||||
const [goal, setGoal] = useState('');
|
||||
@@ -63,7 +65,7 @@ const App: React.FC = () => {
|
||||
const { user } = await loginUser(email, password);
|
||||
setCurrentUser(user);
|
||||
setView('input');
|
||||
toast.success(`欢迎回来,${user.name}!`);
|
||||
toast.success(t('welcomeBack', { name: user.name }));
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
setError(err.message);
|
||||
@@ -79,7 +81,7 @@ const App: React.FC = () => {
|
||||
const { user } = await loginUser(email, password);
|
||||
setCurrentUser(user);
|
||||
setView('input');
|
||||
toast.success('注册成功!');
|
||||
toast.success(t('signupSuccess'));
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
setError(err.message);
|
||||
@@ -102,7 +104,7 @@ const App: React.FC = () => {
|
||||
setGoal(userGoal);
|
||||
setView('loading');
|
||||
setError(null);
|
||||
setGenProgress({ progress: 5, message: '准备中...', step: 'analyzing' });
|
||||
setGenProgress({ progress: 5, message: t('preparing'), step: 'analyzing' });
|
||||
try {
|
||||
const plan = await generatePlan(userGoal, additionalInfo, (event: GenerateProgressEvent) => {
|
||||
setGenProgress({
|
||||
@@ -114,15 +116,15 @@ const App: React.FC = () => {
|
||||
setCurrentPlan(plan);
|
||||
setGenProgress(null);
|
||||
setView('planner');
|
||||
toast.success('计划生成成功!');
|
||||
toast.success(t('planReady'));
|
||||
} catch (err) {
|
||||
setGenProgress(null);
|
||||
if (err instanceof Error) {
|
||||
setError(err.message);
|
||||
toast.error(err.message);
|
||||
} else {
|
||||
setError("An unknown error occurred.");
|
||||
toast.error("An unknown error occurred.");
|
||||
setError(t('unknownError'));
|
||||
toast.error(t('unknownError'));
|
||||
}
|
||||
setView('error');
|
||||
}
|
||||
@@ -188,12 +190,12 @@ const App: React.FC = () => {
|
||||
if (statusResult.level_up) {
|
||||
setLevelUpInfo({ oldLevel: statusResult.old_level, newLevel: statusResult.new_level });
|
||||
setTimeout(() => setLevelUpInfo(null), 3000);
|
||||
toast.success(`🎉 升级了!Lv.${statusResult.old_level} → Lv.${statusResult.new_level}`);
|
||||
toast.success(t('levelUp', { old: statusResult.old_level, next: statusResult.new_level }));
|
||||
}
|
||||
|
||||
// All done bonus notification
|
||||
if (statusResult.all_done_bonus > 0) {
|
||||
toast.success(`🏆 所有任务完成!获得 ${statusResult.all_done_bonus} XP 奖励!`);
|
||||
toast.success(t('allDoneBonus', { xp: statusResult.all_done_bonus }));
|
||||
}
|
||||
|
||||
if (cascadeParentTasks.length > 0) {
|
||||
@@ -242,11 +244,11 @@ const App: React.FC = () => {
|
||||
if (statusResult.level_up) {
|
||||
setLevelUpInfo({ oldLevel: statusResult.old_level, newLevel: statusResult.new_level });
|
||||
setTimeout(() => setLevelUpInfo(null), 3000);
|
||||
toast.success(`🎉 升级了!Lv.${statusResult.old_level} → Lv.${statusResult.new_level}`);
|
||||
toast.success(t('levelUp', { old: statusResult.old_level, next: statusResult.new_level }));
|
||||
}
|
||||
|
||||
if (statusResult.all_done_bonus > 0) {
|
||||
toast.success(`🏆 所有任务完成!获得 ${statusResult.all_done_bonus} XP 奖励!`);
|
||||
toast.success(t('allDoneBonus', { xp: statusResult.all_done_bonus }));
|
||||
}
|
||||
|
||||
setCurrentPlan(prev => {
|
||||
@@ -292,7 +294,7 @@ const App: React.FC = () => {
|
||||
);
|
||||
return { ...prev, tasks: updateTaskInTree(prev.tasks) };
|
||||
});
|
||||
toast.success('任务已更新');
|
||||
toast.success(t('taskUpdated'));
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
toast.error(err.message);
|
||||
@@ -316,7 +318,7 @@ const App: React.FC = () => {
|
||||
);
|
||||
return { ...prev, tasks: removeTasks(prev.tasks) };
|
||||
});
|
||||
toast.success('任务已删除');
|
||||
toast.success(t('taskDeleted'));
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
toast.error(err.message);
|
||||
@@ -361,7 +363,7 @@ const App: React.FC = () => {
|
||||
};
|
||||
return { ...prev, tasks: addTaskToTree(prev.tasks) };
|
||||
});
|
||||
toast.success('任务已添加');
|
||||
toast.success(t('taskAdded'));
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
toast.error(err.message);
|
||||
@@ -392,7 +394,7 @@ const App: React.FC = () => {
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
toast.error('排序更新失败');
|
||||
toast.error(t('reorderFail'));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -452,13 +454,13 @@ const App: React.FC = () => {
|
||||
case 'error':
|
||||
return (
|
||||
<div className="bg-red-100 dark:bg-red-900/30 border border-red-400 dark:border-red-700 text-red-700 dark:text-red-300 px-4 py-3 rounded-lg text-center">
|
||||
<strong className="font-bold">Oops! Something went wrong.</strong>
|
||||
<strong className="font-bold">{t('oops')}</strong>
|
||||
<p className="block sm:inline">{error}</p>
|
||||
<button
|
||||
onClick={handleStartOver}
|
||||
className="mt-4 bg-red-600 text-white font-semibold px-4 py-2 rounded-lg hover:bg-red-700 transition-colors"
|
||||
>
|
||||
Try Again
|
||||
{t('tryAgain')}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
@@ -468,7 +470,7 @@ const App: React.FC = () => {
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return <Loader message="Loading..." />;
|
||||
return <Loader message={t('loading')} />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -492,7 +494,7 @@ const App: React.FC = () => {
|
||||
</div>
|
||||
</main>
|
||||
{view === 'landing' && <Footer />}
|
||||
{view === 'loading' && !genProgress && <Loader message="Generating your plan with AI..." />}
|
||||
{view === 'loading' && !genProgress && <Loader message={t('generating')} />}
|
||||
{view === 'loading' && genProgress && (
|
||||
<GenerationProgress
|
||||
progress={genProgress.progress}
|
||||
|
||||
Reference in New Issue
Block a user