From 9b81c88250bc534105cc651b3ec53108cfc88bbc Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 2 Feb 2025 13:21:14 +0800 Subject: [PATCH] feat: i18n support --- .../public/locales/en/translation.json | 28 ++++++++ .../public/locales/zh/translation.json | 28 ++++++++ web/default/src/pages/Home/index.js | 71 +++++++++++-------- 3 files changed, 96 insertions(+), 31 deletions(-) diff --git a/web/default/public/locales/en/translation.json b/web/default/public/locales/en/translation.json index cbe3f6ae..4e5a4e01 100644 --- a/web/default/public/locales/en/translation.json +++ b/web/default/public/locales/en/translation.json @@ -726,5 +726,33 @@ "built_by_name": "JustSong", "license": ", source code is licensed under the", "mit": "MIT License" + }, + "home": { + "welcome": { + "title": "Welcome to One API", + "description": "One API is a LLM API management and distribution system that helps you better manage and use LLM APIs from various providers.", + "login_notice": "To use the service, please login or register first." + }, + "system_status": { + "title": "System Status", + "info": { + "title": "System Information", + "name": "Name: ", + "version": "Version: ", + "source": "Source: ", + "source_link": "GitHub Repository", + "start_time": "Start Time: " + }, + "config": { + "title": "System Configuration", + "email_verify": "Email Verification: ", + "github_oauth": "GitHub OAuth: ", + "wechat_login": "WeChat Login: ", + "turnstile": "Turnstile Check: ", + "enabled": "Enabled", + "disabled": "Disabled" + } + }, + "loading_failed": "Failed to load homepage content..." } } diff --git a/web/default/public/locales/zh/translation.json b/web/default/public/locales/zh/translation.json index bcbbfc68..64c096e1 100644 --- a/web/default/public/locales/zh/translation.json +++ b/web/default/public/locales/zh/translation.json @@ -730,5 +730,33 @@ "built_by_name": "JustSong", "license": "构建,源代码遵循", "mit": "MIT 协议" + }, + "home": { + "welcome": { + "title": "欢迎使用 One API", + "description": "One API 是一个 LLM API 接口管理和分发系统,可以帮助您更好地管理和使用各大厂商的 LLM API。", + "login_notice": "如需使用,请先登录或注册。" + }, + "system_status": { + "title": "系统状况", + "info": { + "title": "系统信息", + "name": "名称:", + "version": "版本:", + "source": "源码:", + "source_link": "GitHub 仓库", + "start_time": "启动时间:" + }, + "config": { + "title": "系统配置", + "email_verify": "邮箱验证:", + "github_oauth": "GitHub 身份验证:", + "wechat_login": "微信身份验证:", + "turnstile": "Turnstile 校验:", + "enabled": "已启用", + "disabled": "未启用" + } + }, + "loading_failed": "加载首页内容失败..." } } diff --git a/web/default/src/pages/Home/index.js b/web/default/src/pages/Home/index.js index 95c7b543..736f5b5e 100644 --- a/web/default/src/pages/Home/index.js +++ b/web/default/src/pages/Home/index.js @@ -1,5 +1,6 @@ import React, { useContext, useEffect, useState } from 'react'; -import { Card, Grid, Header, Segment } from 'semantic-ui-react'; +import { useTranslation } from 'react-i18next'; +import { Card, Grid, Header } from 'semantic-ui-react'; import { API, showError, showNotice, timestamp2string } from '../../helpers'; import { StatusContext } from '../../context/Status'; import { marked } from 'marked'; @@ -7,6 +8,7 @@ import { UserContext } from '../../context/User'; import { Link } from 'react-router-dom'; const Home = () => { + const { t } = useTranslation(); const [statusState, statusDispatch] = useContext(StatusContext); const [homePageContentLoaded, setHomePageContentLoaded] = useState(false); const [homePageContent, setHomePageContent] = useState(''); @@ -40,7 +42,7 @@ const Home = () => { localStorage.setItem('home_page_content', content); } else { showError(message); - setHomePageContent('加载首页内容失败...'); + setHomePageContent(t('home.loading_failed')); } setHomePageContentLoaded(true); }; @@ -61,17 +63,14 @@ const Home = () => {
- 欢迎使用 One API + + {t('home.welcome.title')} + -

- One API 是一个 LLM API - 接口管理和分发系统,可以帮助您更好地管理和使用各大厂商的 LLM - API。 -

+

{t('home.welcome.description')}

{!userState.user && (

- 如需使用,请先登录或 - 注册。 + {t('home.welcome.login_notice')}

)}
@@ -80,7 +79,7 @@ const Home = () => { -
系统状况
+
{t('home.system_status.title')}
@@ -92,7 +91,7 @@ const Home = () => {
- 系统信息 + {t('home.system_status.info.title')}
{ }} > - 名称: + + {t('home.system_status.info.name')} + {statusState?.status?.system_name}

{ }} > - 版本: + + {t('home.system_status.info.version')} + {statusState?.status?.version || 'unknown'} @@ -130,13 +133,15 @@ const Home = () => { }} > - 源码: + + {t('home.system_status.info.source')} + - GitHub 仓库 + {t('home.system_status.info.source_link')}

{ }} > - 启动时间: + + {t('home.system_status.info.start_time')} + {getStartTimeString()}

@@ -164,7 +171,7 @@ const Home = () => {
- 系统配置 + {t('home.system_status.config.title')}
{ }} > - 邮箱验证: + + {t('home.system_status.config.email_verify')} + { }} > {statusState?.status?.email_verification - ? '已启用' - : '未启用'} + ? t('home.system_status.config.enabled') + : t('home.system_status.config.disabled')}

{ > - GitHub 身份验证: + {t('home.system_status.config.github_oauth')} { }} > {statusState?.status?.github_oauth - ? '已启用' - : '未启用'} + ? t('home.system_status.config.enabled') + : t('home.system_status.config.disabled')}

{ > - 微信身份验证: + {t('home.system_status.config.wechat_login')} { }} > {statusState?.status?.wechat_login - ? '已启用' - : '未启用'} + ? t('home.system_status.config.enabled') + : t('home.system_status.config.disabled')}

{ > - Turnstile 校验: + {t('home.system_status.config.turnstile')} { }} > {statusState?.status?.turnstile_check - ? '已启用' - : '未启用'} + ? t('home.system_status.config.enabled') + : t('home.system_status.config.disabled')}

@@ -270,7 +279,7 @@ const Home = () => {
-
{' '} +
) : ( <>