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

@@ -1,5 +1,5 @@
name: 漏洞反馈 name: 漏洞反馈
description: 报错或漏洞请使用这个模板创建不使用此模板创建的异常、漏洞相关issue将被直接关闭。由于自己操作不当/不甚了解所用技术栈引起的网络连接问题恕无法解决,请勿提 issue。容器间网络连接问题参考文档 https://docs.langbot.app/deploy/network-details.html description: 报错或漏洞请使用这个模板创建不使用此模板创建的异常、漏洞相关issue将被直接关闭。由于自己操作不当/不甚了解所用技术栈引起的网络连接问题恕无法解决,请勿提 issue。容器间网络连接问题参考文档 https://docs.langbot.app/zh/workshop/network-details.html
title: "[Bug]: " title: "[Bug]: "
labels: ["bug?"] labels: ["bug?"]
body: body:

14
main.py
View File

@@ -10,8 +10,8 @@ asciiart = r"""
|____\__,_|_||_\__, |___/\___/\__| |____\__,_|_||_\__, |___/\___/\__|
|___/ |___/
⭐️开源地址: https://github.com/RockChinQ/LangBot ⭐️ Open Source 开源地址: https://github.com/RockChinQ/LangBot
📖文档地址: https://docs.langbot.app 📖 Documentation 文档地址: https://docs.langbot.app
""" """
@@ -28,10 +28,14 @@ async def main_entry(loop: asyncio.AbstractEventLoop):
if missing_deps: if missing_deps:
print('以下依赖包未安装,将自动安装,请完成后重启程序:') print('以下依赖包未安装,将自动安装,请完成后重启程序:')
print(
'These dependencies are missing, they will be installed automatically, please restart the program after completion:'
)
for dep in missing_deps: for dep in missing_deps:
print('-', dep) print('-', dep)
await deps.install_deps(missing_deps) await deps.install_deps(missing_deps)
print('已自动安装缺失的依赖包,请重启程序。') print('已自动安装缺失的依赖包,请重启程序。')
print('The missing dependencies have been installed automatically, please restart the program.')
sys.exit(0) sys.exit(0)
# check plugin deps # check plugin deps
@@ -53,6 +57,7 @@ async def main_entry(loop: asyncio.AbstractEventLoop):
if generated_files: if generated_files:
print('以下文件不存在,已自动生成:') print('以下文件不存在,已自动生成:')
print('Following files do not exist and have been automatically generated:')
for file in generated_files: for file in generated_files:
print('-', file) print('-', file)
@@ -69,9 +74,10 @@ if __name__ == '__main__':
if sys.version_info < (3, 10, 1): if sys.version_info < (3, 10, 1):
print('需要 Python 3.10.1 及以上版本,当前 Python 版本为:', sys.version) print('需要 Python 3.10.1 及以上版本,当前 Python 版本为:', sys.version)
input('按任意键退出...') input('按任意键退出...')
print('Your Python version is not supported. Please exit the program by pressing any key.')
exit(1) exit(1)
# 检查本目录是否有main.py且包含LangBot字符串 # Check if the current directory is the LangBot project root directory
invalid_pwd = False invalid_pwd = False
if not os.path.exists('main.py'): if not os.path.exists('main.py'):
@@ -84,6 +90,8 @@ if __name__ == '__main__':
if invalid_pwd: if invalid_pwd:
print('请在 LangBot 项目根目录下以命令形式运行此程序。') print('请在 LangBot 项目根目录下以命令形式运行此程序。')
input('按任意键退出...') input('按任意键退出...')
print('Please run this program in the LangBot project root directory in command form.')
print('Press any key to exit...')
exit(1) exit(1)
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()

View File

@@ -158,7 +158,10 @@ class Application:
"""打印访问 webui 的提示""" """打印访问 webui 的提示"""
if not os.path.exists(os.path.join('.', 'web/out')): if not os.path.exists(os.path.join('.', 'web/out')):
self.logger.warning('WebUI 文件缺失,请根据文档获取https://docs.langbot.app/webui/intro.html') self.logger.warning('WebUI 文件缺失,请根据文档部署https://docs.langbot.app/zh')
self.logger.warning(
'WebUI files are missing, please deploy according to the documentation: https://docs.langbot.app/en'
)
return return
host_ip = '127.0.0.1' host_ip = '127.0.0.1'

View File

@@ -199,9 +199,9 @@ class VersionManager:
try: try:
if await self.ap.ver_mgr.is_new_version_available(): if await self.ap.ver_mgr.is_new_version_available():
return ( return (
'有新版本可用,根据文档更新https://docs.langbot.app/deploy/update.html', 'New version available:\n有新版本可用,根据文档更新: \nhttps://docs.langbot.app/zh/deploy/update.html',
logging.INFO, logging.INFO,
) )
except Exception as e: except Exception as e:
return f'检查版本更新时出错: {e}', logging.WARNING return f'Error checking version update: {e}', logging.WARNING

View File

@@ -138,7 +138,18 @@ export default function HomeSidebar({
<SidebarChild <SidebarChild
onClick={() => { onClick={() => {
// open docs.langbot.app // 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} isSelected={false}
icon={ icon={

View File

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

View File

@@ -22,7 +22,10 @@ export const sidebarConfigList = [
), ),
route: '/home/bots', route: '/home/bots',
description: t('bots.description'), 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({ new SidebarChildVO({
id: 'models', id: 'models',
@@ -39,7 +42,10 @@ export const sidebarConfigList = [
), ),
route: '/home/models', route: '/home/models',
description: t('models.description'), 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({ new SidebarChildVO({
id: 'pipelines', id: 'pipelines',
@@ -56,7 +62,10 @@ export const sidebarConfigList = [
), ),
route: '/home/pipelines', route: '/home/pipelines',
description: t('pipelines.description'), 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({ new SidebarChildVO({
id: 'plugins', id: 'plugins',
@@ -73,6 +82,9 @@ export const sidebarConfigList = [
), ),
route: '/home/plugins', route: '/home/plugins',
description: t('plugins.description'), 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 styles from './HomeTittleBar.module.css';
import { I18nText } from '@/app/infra/entities/api';
export default function HomeTitleBar({ export default function HomeTitleBar({
title, title,
@@ -7,7 +9,7 @@ export default function HomeTitleBar({
}: { }: {
title: string; title: string;
subtitle: string; subtitle: string;
helpLink: string; helpLink: I18nText;
}) { }) {
return ( return (
<div className={`${styles.titleBarContainer}`}> <div className={`${styles.titleBarContainer}`}>
@@ -15,7 +17,7 @@ export default function HomeTitleBar({
<div className={`${styles.subtitleText}`}> <div className={`${styles.subtitleText}`}>
{subtitle} {subtitle}
<span className={`${styles.helpLink}`}> <span className={`${styles.helpLink}`}>
<a href={helpLink} target="_blank" rel="noopener noreferrer"> <a href={i18nObj(helpLink)} target="_blank" rel="noopener noreferrer">
<svg <svg
className="w-[1rem] h-[1rem]" className="w-[1rem] h-[1rem]"
xmlns="http://www.w3.org/2000/svg" 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 HomeTitleBar from '@/app/home/components/home-titlebar/HomeTitleBar';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild'; import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild';
import { I18nText } from '@/app/infra/entities/api';
export default function HomeLayout({ export default function HomeLayout({
children, children,
@@ -13,7 +14,10 @@ export default function HomeLayout({
}>) { }>) {
const [title, setTitle] = useState<string>(''); const [title, setTitle] = useState<string>('');
const [subtitle, setSubtitle] = 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) => { const onSelectedChangeAction = (child: SidebarChildVO) => {
setTitle(child.name); setTitle(child.name);
setSubtitle(child.description); setSubtitle(child.description);

View File

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

View File

@@ -38,6 +38,13 @@ const enUS = {
deleteError: 'Delete failed: ', deleteError: 'Delete failed: ',
addRound: 'Add Round', 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: { models: {
title: 'Models', title: 'Models',
description: 'Configure and manage models that can be used in pipelines', description: 'Configure and manage models that can be used in pipelines',

View File

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