diff --git a/README.md b/README.md index b3e3f3d..409c4a4 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ npm run build 2、单独域名部署,设置环境变量ONLY_LIVE=yes,使用正常编译即可 +#### 多语言部署 +应用默认使用简体中文进行编译;如果需要指定其他语言需要设置环境变量:`APP_LANGUAGE`; + +`APP_LANGUAGE`目前支持的值有:`zh-CN`(中文)、`en-US`(英语)。 + **使用docker** [x] TODO diff --git a/src/components/button-batch.tsx b/src/components/button-batch.tsx index 434a05b..e174bd2 100644 --- a/src/components/button-batch.tsx +++ b/src/components/button-batch.tsx @@ -56,7 +56,7 @@ export default function ButtonBatch( if(confirmMessage){ modal.confirm({ wrapClassName: 'root-modal-confirm', - title: title || t('confirm.title'), + title: , centered: true, icon: , content: confirmMessage, diff --git a/src/components/document.tsx b/src/components/document.tsx index 1fb21a9..a3bddf5 100644 --- a/src/components/document.tsx +++ b/src/components/document.tsx @@ -9,6 +9,6 @@ export const DocumentTitle: React.FC = ({children, title}) = if (title || children) { document.title = title || children || ''; } - }, []); + }, [title,children]); return <> } \ No newline at end of file diff --git a/src/hooks/useGlobalConfig.ts b/src/hooks/useGlobalConfig.ts new file mode 100644 index 0000000..c6f6784 --- /dev/null +++ b/src/hooks/useGlobalConfig.ts @@ -0,0 +1,13 @@ +const globalConfig:{ + i18n?:I18n +} = { + +} + +function useGlobalConfig(){ + return { + globalConfig + } +} + +export default useGlobalConfig; \ No newline at end of file diff --git a/src/i18n/config.ts b/src/i18n/config.ts index 33bac84..0a0e201 100644 --- a/src/i18n/config.ts +++ b/src/i18n/config.ts @@ -6,7 +6,6 @@ import LangCN from './translations/zh-CN.json'; console.log('AppConfig',AppMode) i18next.use(initReactI18next).init({ debug: true, - lng:'en-US', fallbackLng: 'en-US', resources: { 'en-US': {translation:LangEN}, diff --git a/src/i18n/translations/en-US.json b/src/i18n/translations/en-US.json index 1a20b84..091909f 100644 --- a/src/i18n/translations/en-US.json +++ b/src/i18n/translations/en-US.json @@ -128,7 +128,7 @@ }, "video": { "delete_confirm_title": "Are you sure you want to delete this video?", - "delete_confirm": "These videos will be deleted.They can be recovered from the “news” page. ", + "delete_confirm": "These videos will be deleted.
They can be recovered from the “news” page. ", "delete_description": "Are you sure you want to delete these {{count}} videos?", "delete_empty": "Select the video you want to delete", "download": "Download", diff --git a/src/pages/library/components/search-form.tsx b/src/pages/library/components/search-form.tsx index 4e7da49..2353301 100644 --- a/src/pages/library/components/search-form.tsx +++ b/src/pages/library/components/search-form.tsx @@ -49,7 +49,7 @@ export default function SearchForm({onSearch}: Props) { placeholder={t("history.search_key")} /> diff --git a/src/pages/library/index.tsx b/src/pages/library/index.tsx index 0a0779f..8110de8 100644 --- a/src/pages/library/index.tsx +++ b/src/pages/library/index.tsx @@ -106,17 +106,17 @@ export default function LibraryIndex() {
- - {t('select.total',{count:data?.list.length || 0})} + + {t('select.total',{count:data?.list?.length || 0})} {t('select.pushed',{count:state.pushedCount})} {t('select.selected_some',{count:checkedIdArray.length})} - - handleAllCheckedChange(e.target.checked)}/>
@@ -161,7 +161,7 @@ export default function LibraryIndex() { icon={} title={t('video.delete_description',{count:checkedIdArray.length})} emptyMessage={t('video.delete_empty')} - confirmMessage={t('video.delete_confirm')} + confirmMessage={} onProcess={deleteHistories} >{t('delete_batch')}} {checkedIdArray?.length > 0 && { const {t,i18n:langConfig} = useTranslation(); @@ -37,6 +39,7 @@ const AppRouter = () => { }else{ dayjs.locale('en') } + globalConfig.i18n = i18n langConfig.changeLanguage(i18n).then(()=>console.log('change lang to ',i18n)) }, [i18n]) diff --git a/src/routes/layout/dashboard-layout.tsx b/src/routes/layout/dashboard-layout.tsx index 5b74b32..b0c9beb 100644 --- a/src/routes/layout/dashboard-layout.tsx +++ b/src/routes/layout/dashboard-layout.tsx @@ -1,4 +1,4 @@ -import {Outlet, useLocation, useNavigate} from "react-router-dom"; +import {Outlet, useLocation, useNavigate, useSearchParams} from "react-router-dom"; import {Button, Divider, Dropdown, MenuProps} from "antd"; import React, {useEffect} from "react"; @@ -78,6 +78,7 @@ const NavigationUserContainer = () => { } export const BaseLayout: React.FC = ({children}) => { const {i18n,onChangeLocalization} = useConfig(); + const [params] = useSearchParams(); return (
@@ -86,6 +87,7 @@ export const BaseLayout: React.FC = ({children}) => {
+ {params.get('lang') || AppConfig.APP_LANG == 'multiple' &&
{ i18n == 'zh-CN'?( @@ -93,6 +95,7 @@ export const BaseLayout: React.FC = ({children}) => { ) } +
}
@@ -116,7 +119,7 @@ const DashboardLayout: React.FC<{ children?: React.ReactNode }> = ({children}) = } },[]) return -
first path:{defaultCache.firstLoadPath}
+
{defaultCache.firstLoadPath}
{children ? children : } diff --git a/src/service/request.ts b/src/service/request.ts index a082ab7..e7eeaef 100644 --- a/src/service/request.ts +++ b/src/service/request.ts @@ -2,6 +2,7 @@ import axios from 'axios'; import {stringify} from 'qs' import {BizError} from './types'; import {getAuthToken} from "@/hooks/useAuth.ts"; +import useGlobalConfig from '@/hooks/useGlobalConfig'; const JSON_FORMAT: string = 'application/json'; const REQUEST_TIMEOUT = 300000; // 超时时长5min @@ -11,10 +12,19 @@ const Axios = axios.create({ headers: {'Content-Type': JSON_FORMAT} }) - +const {globalConfig} = useGlobalConfig(); // 请求前拦截 Axios.interceptors.request.use(config => { const token = getAuthToken(); + if (globalConfig.i18n){ + let url = config.url; + if(url){ + url += (url.indexOf('?') == -1?'?':'&') + `lang=${globalConfig.i18n || ''}` + config.url = url; + } + + //config.headers['language'] = globalConfig.i18n; + } if (token) { config.headers['Token'] = `${token}`; } diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 7ce12cf..2836d38 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -13,6 +13,7 @@ declare const AppConfig: { AUTHED_PERSON_DATA_KEY: string; API_PREFIX: string; ONLY_LIVE: string; + APP_LANG: string; }; declare const AppMode: 'test' | 'production' | 'development'; diff --git a/vite.config.ts b/vite.config.ts index 699d0a8..9ef559a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -22,6 +22,7 @@ export default defineConfig(({mode}) => { AUTH_TOKEN_KEY: process.env.AUTH_TOKEN_KEY || AUTH_TOKEN_KEY, AUTHED_PERSON_DATA_KEY: process.env.AUTHED_PERSON_DATA_KEY || 'digital-person-user-info', ONLY_LIVE: process.env.ONLY_LIVE || 'no', + APP_LANG: process.env.APP_LANGUAGE || 'zh-CN' }), AppMode: JSON.stringify(mode), AppBuildVersion: JSON.stringify(AppPackage.name + '-' + AppPackage.version + '-' + dayjs().format('YYYYMMDDHH_mmss'))