From 347da6142e55ef863d6650ea3ee3043d51dec037 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Thu, 15 May 2025 10:40:36 +0800 Subject: [PATCH] perf: multi language --- .github/ISSUE_TEMPLATE/bug-report.yml | 2 +- main.py | 14 ++++++++++--- pkg/core/app.py | 5 ++++- pkg/utils/version.py | 4 ++-- .../components/home-sidebar/HomeSidebar.tsx | 13 +++++++++++- .../home-sidebar/HomeSidebarChild.tsx | 5 +++-- .../home-sidebar/sidbarConfigList.tsx | 20 +++++++++++++++---- .../components/home-titlebar/HomeTitleBar.tsx | 6 ++++-- web/src/app/home/layout.tsx | 6 +++++- web/src/app/not-found.tsx | 14 ++++++------- web/src/i18n/locales/en-US.ts | 7 +++++++ web/src/i18n/locales/zh-Hans.ts | 8 ++++++++ 12 files changed, 80 insertions(+), 24 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 546e10be..3695a3fb 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -1,5 +1,5 @@ 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]: " labels: ["bug?"] body: diff --git a/main.py b/main.py index 8be603c6..8f25f826 100644 --- a/main.py +++ b/main.py @@ -10,8 +10,8 @@ asciiart = r""" |____\__,_|_||_\__, |___/\___/\__| |___/ -⭐️开源地址: https://github.com/RockChinQ/LangBot -📖文档地址: https://docs.langbot.app +⭐️ Open Source 开源地址: https://github.com/RockChinQ/LangBot +📖 Documentation 文档地址: https://docs.langbot.app """ @@ -28,10 +28,14 @@ async def main_entry(loop: asyncio.AbstractEventLoop): if missing_deps: print('以下依赖包未安装,将自动安装,请完成后重启程序:') + print( + 'These dependencies are missing, they will be installed automatically, please restart the program after completion:' + ) for dep in missing_deps: print('-', dep) await deps.install_deps(missing_deps) print('已自动安装缺失的依赖包,请重启程序。') + print('The missing dependencies have been installed automatically, please restart the program.') sys.exit(0) # check plugin deps @@ -53,6 +57,7 @@ async def main_entry(loop: asyncio.AbstractEventLoop): if generated_files: print('以下文件不存在,已自动生成:') + print('Following files do not exist and have been automatically generated:') for file in generated_files: print('-', file) @@ -69,9 +74,10 @@ if __name__ == '__main__': if sys.version_info < (3, 10, 1): print('需要 Python 3.10.1 及以上版本,当前 Python 版本为:', sys.version) input('按任意键退出...') + print('Your Python version is not supported. Please exit the program by pressing any key.') exit(1) - # 检查本目录是否有main.py,且包含LangBot字符串 + # Check if the current directory is the LangBot project root directory invalid_pwd = False if not os.path.exists('main.py'): @@ -84,6 +90,8 @@ if __name__ == '__main__': if invalid_pwd: print('请在 LangBot 项目根目录下以命令形式运行此程序。') input('按任意键退出...') + print('Please run this program in the LangBot project root directory in command form.') + print('Press any key to exit...') exit(1) loop = asyncio.new_event_loop() diff --git a/pkg/core/app.py b/pkg/core/app.py index ad1d45c7..910caa75 100644 --- a/pkg/core/app.py +++ b/pkg/core/app.py @@ -158,7 +158,10 @@ class Application: """打印访问 webui 的提示""" 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 host_ip = '127.0.0.1' diff --git a/pkg/utils/version.py b/pkg/utils/version.py index 46c1aad6..ec0683c3 100644 --- a/pkg/utils/version.py +++ b/pkg/utils/version.py @@ -199,9 +199,9 @@ class VersionManager: try: if await self.ap.ver_mgr.is_new_version_available(): return ( - '有新版本可用,根据文档更新:https://docs.langbot.app/deploy/update.html', + 'New version available:\n有新版本可用,根据文档更新: \nhttps://docs.langbot.app/zh/deploy/update.html', logging.INFO, ) except Exception as e: - return f'检查版本更新时出错: {e}', logging.WARNING + return f'Error checking version update: {e}', logging.WARNING diff --git a/web/src/app/home/components/home-sidebar/HomeSidebar.tsx b/web/src/app/home/components/home-sidebar/HomeSidebar.tsx index 18af3e96..876baf33 100644 --- a/web/src/app/home/components/home-sidebar/HomeSidebar.tsx +++ b/web/src/app/home/components/home-sidebar/HomeSidebar.tsx @@ -138,7 +138,18 @@ export default function HomeSidebar({ { // 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={ diff --git a/web/src/app/home/components/home-sidebar/HomeSidebarChild.tsx b/web/src/app/home/components/home-sidebar/HomeSidebarChild.tsx index 0e98dcc0..27f946b0 100644 --- a/web/src/app/home/components/home-sidebar/HomeSidebarChild.tsx +++ b/web/src/app/home/components/home-sidebar/HomeSidebarChild.tsx @@ -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; diff --git a/web/src/app/home/components/home-sidebar/sidbarConfigList.tsx b/web/src/app/home/components/home-sidebar/sidbarConfigList.tsx index c98c4956..e21317d6 100644 --- a/web/src/app/home/components/home-sidebar/sidbarConfigList.tsx +++ b/web/src/app/home/components/home-sidebar/sidbarConfigList.tsx @@ -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', + }, }), ]; diff --git a/web/src/app/home/components/home-titlebar/HomeTitleBar.tsx b/web/src/app/home/components/home-titlebar/HomeTitleBar.tsx index 99e7339f..5568c1a3 100644 --- a/web/src/app/home/components/home-titlebar/HomeTitleBar.tsx +++ b/web/src/app/home/components/home-titlebar/HomeTitleBar.tsx @@ -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 (
@@ -15,7 +17,7 @@ export default function HomeTitleBar({
{subtitle} - + ) { const [title, setTitle] = useState(''); const [subtitle, setSubtitle] = useState(''); - const [helpLink, setHelpLink] = useState(''); + const [helpLink, setHelpLink] = useState({ + en_US: '', + zh_Hans: '', + }); const onSelectedChangeAction = (child: SidebarChildVO) => { setTitle(child.name); setSubtitle(child.description); diff --git a/web/src/app/not-found.tsx b/web/src/app/not-found.tsx index 90941c7a..56344679 100644 --- a/web/src/app/not-found.tsx +++ b/web/src/app/not-found.tsx @@ -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 (
@@ -18,11 +20,10 @@ export default function NotFound() { {/* 错误文本 */}

- 页面不存在 + {t('notFound.title')}

- 您要查找的页面似乎不存在。请检查您输入的 URL - 是否正确,或者返回首页。 + {t('notFound.description')}

@@ -33,26 +34,25 @@ export default function NotFound() { onClick={() => router.back()} className="h-9 px-4 cursor-pointer" > - 上一级 + {t('notFound.back')}
{/* 帮助文档链接 */}
diff --git a/web/src/i18n/locales/en-US.ts b/web/src/i18n/locales/en-US.ts index 8a603a60..f0112e30 100644 --- a/web/src/i18n/locales/en-US.ts +++ b/web/src/i18n/locales/en-US.ts @@ -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', diff --git a/web/src/i18n/locales/zh-Hans.ts b/web/src/i18n/locales/zh-Hans.ts index c028c4ca..b31a008c 100644 --- a/web/src/i18n/locales/zh-Hans.ts +++ b/web/src/i18n/locales/zh-Hans.ts @@ -38,6 +38,14 @@ const zhHans = { deleteError: '删除失败:', addRound: '添加回合', }, + notFound: { + title: '页面不存在', + description: + '您要查找的页面似乎不存在。请检查您输入的 URL 是否正确,或者返回首页。', + back: '上一级', + home: '返回主页', + help: '查看帮助文档', + }, models: { title: '模型配置', description: '配置和管理可在流水线中使用的模型',