perf: multi language

This commit is contained in:
Junyan Qin
2025-05-15 10:40:36 +08:00
parent a9f4dc517a
commit 347da6142e
12 changed files with 80 additions and 24 deletions

View File

@@ -138,7 +138,18 @@ export default function HomeSidebar({
<SidebarChild
onClick={() => {
// open docs.langbot.app
window.open('https://docs.langbot.app', '_blank');
const language = localStorage.getItem('langbot_language');
if (language === 'zh-Hans') {
window.open(
'https://docs.langbot.app/zh/insight/guide.html',
'_blank',
);
} else {
window.open(
'https://docs.langbot.app/en/insight/guide.html',
'_blank',
);
}
}}
isSelected={false}
icon={

View File

@@ -1,4 +1,5 @@
import styles from './HomeSidebar.module.css';
import { I18nText } from '@/app/infra/entities/api';
export interface ISidebarChildVO {
id: string;
@@ -6,7 +7,7 @@ export interface ISidebarChildVO {
name: string;
route: string;
description: string;
helpLink: string;
helpLink: I18nText;
}
export class SidebarChildVO {
@@ -15,7 +16,7 @@ export class SidebarChildVO {
name: string;
route: string;
description: string;
helpLink: string;
helpLink: I18nText;
constructor(props: ISidebarChildVO) {
this.id = props.id;

View File

@@ -22,7 +22,10 @@ export const sidebarConfigList = [
),
route: '/home/bots',
description: t('bots.description'),
helpLink: 'https://docs.langbot.app/zh/deploy/platforms/readme.html',
helpLink: {
en_US: 'https://docs.langbot.app/en/deploy/platforms/readme.html',
zh_Hans: 'https://docs.langbot.app/zh/deploy/platforms/readme.html',
},
}),
new SidebarChildVO({
id: 'models',
@@ -39,7 +42,10 @@ export const sidebarConfigList = [
),
route: '/home/models',
description: t('models.description'),
helpLink: 'https://docs.langbot.app/zh/deploy/models/readme.html',
helpLink: {
en_US: 'https://docs.langbot.app/en/deploy/models/readme.html',
zh_Hans: 'https://docs.langbot.app/zh/deploy/models/readme.html',
},
}),
new SidebarChildVO({
id: 'pipelines',
@@ -56,7 +62,10 @@ export const sidebarConfigList = [
),
route: '/home/pipelines',
description: t('pipelines.description'),
helpLink: 'https://docs.langbot.app/zh/deploy/pipelines/readme.html',
helpLink: {
en_US: 'https://docs.langbot.app/en/deploy/pipelines/readme.html',
zh_Hans: 'https://docs.langbot.app/zh/deploy/pipelines/readme.html',
},
}),
new SidebarChildVO({
id: 'plugins',
@@ -73,6 +82,9 @@ export const sidebarConfigList = [
),
route: '/home/plugins',
description: t('plugins.description'),
helpLink: 'https://docs.langbot.app/zh/plugin/plugin-intro.html',
helpLink: {
en_US: 'https://docs.langbot.app/en/plugin/plugin-intro.html',
zh_Hans: 'https://docs.langbot.app/zh/plugin/plugin-intro.html',
},
}),
];

View File

@@ -1,4 +1,6 @@
import { i18nObj } from '@/i18n/I18nProvider';
import styles from './HomeTittleBar.module.css';
import { I18nText } from '@/app/infra/entities/api';
export default function HomeTitleBar({
title,
@@ -7,7 +9,7 @@ export default function HomeTitleBar({
}: {
title: string;
subtitle: string;
helpLink: string;
helpLink: I18nText;
}) {
return (
<div className={`${styles.titleBarContainer}`}>
@@ -15,7 +17,7 @@ export default function HomeTitleBar({
<div className={`${styles.subtitleText}`}>
{subtitle}
<span className={`${styles.helpLink}`}>
<a href={helpLink} target="_blank" rel="noopener noreferrer">
<a href={i18nObj(helpLink)} target="_blank" rel="noopener noreferrer">
<svg
className="w-[1rem] h-[1rem]"
xmlns="http://www.w3.org/2000/svg"

View File

@@ -5,6 +5,7 @@ import HomeSidebar from '@/app/home/components/home-sidebar/HomeSidebar';
import HomeTitleBar from '@/app/home/components/home-titlebar/HomeTitleBar';
import React, { useState } from 'react';
import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild';
import { I18nText } from '@/app/infra/entities/api';
export default function HomeLayout({
children,
@@ -13,7 +14,10 @@ export default function HomeLayout({
}>) {
const [title, setTitle] = useState<string>('');
const [subtitle, setSubtitle] = useState<string>('');
const [helpLink, setHelpLink] = useState<string>('');
const [helpLink, setHelpLink] = useState<I18nText>({
en_US: '',
zh_Hans: '',
});
const onSelectedChangeAction = (child: SidebarChildVO) => {
setTitle(child.name);
setSubtitle(child.description);

View File

@@ -2,9 +2,11 @@
import { useRouter } from 'next/navigation';
import { Button } from '@/components/ui/button';
import { useTranslation } from 'react-i18next';
export default function NotFound() {
const router = useRouter();
const { t } = useTranslation();
return (
<div className="min-h-screen bg-white flex items-center justify-center">
@@ -18,11 +20,10 @@ export default function NotFound() {
{/* 错误文本 */}
<div className="text-center mb-8">
<h1 className="text-2xl font-normal text-gray-800 mb-2">
{t('notFound.title')}
</h1>
<p className="text-base text-gray-600 max-w-[450px] mx-auto mb-8">
URL
{t('notFound.description')}
</p>
</div>
@@ -33,26 +34,25 @@ export default function NotFound() {
onClick={() => router.back()}
className="h-9 px-4 cursor-pointer"
>
{t('notFound.back')}
</Button>
<Button
variant="outline"
onClick={() => router.push('/home')}
className="h-9 px-4 cursor-pointer"
>
{t('notFound.home')}
</Button>
</div>
{/* 帮助文档链接 */}
<div className="text-center">
<p className="text-sm text-gray-600">
<a
href="https://docs.langbot.app"
className="text-black no-underline hover:underline"
>
{t('notFound.help')}
</a>
</p>
</div>

View File

@@ -38,6 +38,13 @@ const enUS = {
deleteError: 'Delete failed: ',
addRound: 'Add Round',
},
notFound: {
title: 'Page not found',
description: 'The page you are looking for does not exist.',
back: 'Back',
home: 'Home',
help: 'Get Help',
},
models: {
title: 'Models',
description: 'Configure and manage models that can be used in pipelines',

View File

@@ -38,6 +38,14 @@ const zhHans = {
deleteError: '删除失败:',
addRound: '添加回合',
},
notFound: {
title: '页面不存在',
description:
'您要查找的页面似乎不存在。请检查您输入的 URL 是否正确,或者返回首页。',
back: '上一级',
home: '返回主页',
help: '查看帮助文档',
},
models: {
title: '模型配置',
description: '配置和管理可在流水线中使用的模型',