From 562f30237c227547ae62fe66c9e71374d3ad79db Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Mon, 9 Jun 2025 15:59:56 +0800 Subject: [PATCH] fix --- .../[datasetId]/layout-main.tsx | 2 +- .../conversation-history/history-panel.tsx | 4 ++-- .../dataset-config/settings-modal/index.tsx | 2 +- .../components/app/create-app-modal/index.tsx | 2 +- .../components/app/overview/settings/index.tsx | 2 +- .../components/header/account-dropdown/index.tsx | 2 +- web/app/education-apply/education-apply-page.tsx | 2 +- web/app/education-apply/verify-state-modal.tsx | 2 +- web/context/i18n.ts | 16 +++++++++------- web/i18n/language.ts | 12 ------------ 10 files changed, 18 insertions(+), 28 deletions(-) diff --git a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx index b54eb4f181..d28871270f 100644 --- a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx +++ b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx @@ -31,7 +31,7 @@ import { useAppContext } from '@/context/app-context' import Tooltip from '@/app/components/base/tooltip' import LinkedAppsPanel from '@/app/components/base/linked-apps-panel' import useDocumentTitle from '@/hooks/use-document-title' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' export type IAppDetailLayoutProps = { children: React.ReactNode diff --git a/web/app/components/app/configuration/config-prompt/conversation-history/history-panel.tsx b/web/app/components/app/configuration/config-prompt/conversation-history/history-panel.tsx index 72e692be46..94a02945bb 100644 --- a/web/app/components/app/configuration/config-prompt/conversation-history/history-panel.tsx +++ b/web/app/components/app/configuration/config-prompt/conversation-history/history-panel.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next' import OperationBtn from '@/app/components/app/configuration/base/operation-btn' import Panel from '@/app/components/app/configuration/base/feature-panel' import { MessageClockCircle } from '@/app/components/base/icons/src/vender/solid/general' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' type Props = { showWarning: boolean @@ -44,7 +44,7 @@ const HistoryPanel: FC = ({
{t('appDebug.feature.conversationHistory.tip')} {t('appDebug.feature.conversationHistory.learnMore')} diff --git a/web/app/components/app/configuration/dataset-config/settings-modal/index.tsx b/web/app/components/app/configuration/dataset-config/settings-modal/index.tsx index c6629a063e..61e7639fd2 100644 --- a/web/app/components/app/configuration/dataset-config/settings-modal/index.tsx +++ b/web/app/components/app/configuration/dataset-config/settings-modal/index.tsx @@ -31,7 +31,7 @@ import { import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { fetchMembers } from '@/service/common' import type { Member } from '@/models/common' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' type SettingsModalProps = { currentDataset: DataSet onCancel: () => void diff --git a/web/app/components/app/create-app-modal/index.tsx b/web/app/components/app/create-app-modal/index.tsx index 662d550f04..bfb7c43c0d 100644 --- a/web/app/components/app/create-app-modal/index.tsx +++ b/web/app/components/app/create-app-modal/index.tsx @@ -29,7 +29,7 @@ import { NEED_REFRESH_APP_LIST_KEY } from '@/config' import { getRedirection } from '@/utils/app-redirection' import FullScreenModal from '@/app/components/base/fullscreen-modal' import useTheme from '@/hooks/use-theme' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' type CreateAppProps = { onSuccess: () => void diff --git a/web/app/components/app/overview/settings/index.tsx b/web/app/components/app/overview/settings/index.tsx index c4c129a358..c2d98383c4 100644 --- a/web/app/components/app/overview/settings/index.tsx +++ b/web/app/components/app/overview/settings/index.tsx @@ -24,8 +24,8 @@ import { useProviderContext } from '@/context/provider-context' import { useModalContext } from '@/context/modal-context' import type { AppIconSelection } from '@/app/components/base/app-icon-picker' import AppIconPicker from '@/app/components/base/app-icon-picker' -import { useDocLink } from '@/i18n/language' import cn from '@/utils/classnames' +import { useDocLink } from '@/context/i18n' export type ISettingsModalProps = { isChat: boolean diff --git a/web/app/components/header/account-dropdown/index.tsx b/web/app/components/header/account-dropdown/index.tsx index f9d5c00fbf..781b732e2b 100644 --- a/web/app/components/header/account-dropdown/index.tsx +++ b/web/app/components/header/account-dropdown/index.tsx @@ -33,7 +33,7 @@ import { useModalContext } from '@/context/modal-context' import { IS_CLOUD_EDITION } from '@/config' import cn from '@/utils/classnames' import { useGlobalPublicStore } from '@/context/global-public-context' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' export default function AppSelector() { const itemClassName = ` diff --git a/web/app/education-apply/education-apply-page.tsx b/web/app/education-apply/education-apply-page.tsx index 97aa3a5d8b..c8ebae723c 100644 --- a/web/app/education-apply/education-apply-page.tsx +++ b/web/app/education-apply/education-apply-page.tsx @@ -25,7 +25,7 @@ import { EDUCATION_VERIFYING_LOCALSTORAGE_ITEM } from '@/app/education-apply/con import { getLocaleOnClient } from '@/i18n' import { noop } from 'lodash-es' import DifyLogo from '../components/base/logo/dify-logo' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' const EducationApplyAge = () => { const { t } = useTranslation() const locale = getLocaleOnClient() diff --git a/web/app/education-apply/verify-state-modal.tsx b/web/app/education-apply/verify-state-modal.tsx index af206b64f5..f1dc439f7e 100644 --- a/web/app/education-apply/verify-state-modal.tsx +++ b/web/app/education-apply/verify-state-modal.tsx @@ -6,7 +6,7 @@ import { } from '@remixicon/react' import Button from '@/app/components/base/button' import { getLocaleOnClient } from '@/i18n' -import { useDocLink } from '@/i18n/language' +import { useDocLink } from '@/context/i18n' export type IConfirm = { className?: string diff --git a/web/context/i18n.ts b/web/context/i18n.ts index a96f10fb80..1d7cf593c8 100644 --- a/web/context/i18n.ts +++ b/web/context/i18n.ts @@ -3,7 +3,6 @@ import { useContext, } from 'use-context-selector' import type { Locale } from '@/i18n' -import { getLocaleOnClient } from '@/i18n' import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n/language' import { noop } from 'lodash-es' @@ -36,11 +35,14 @@ export const useGetPricingPageLanguage = () => { return getPricingPageLanguage(locale) } -const baseDocUrl = 'https://docs.dify.ai' -export const getDocLink = (path: string, pathMap?: { [index: string]: string }) => { - const docLanguage = getLocaleOnClient() === 'zh-Hans' ? 'zh-hans' : 'en' - const targetPath = (pathMap !== undefined) ? pathMap[docLanguage] || path : path - return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}` +const defaultDocBaseUrl = 'https://docs.dify.ai' +export const useDocLink = (baseUrl?: string): ((path: string, pathMap?: { [index: string]: string }) => string) => { + const { locale } = useI18N() + return (path: string, pathMap?: { [index: string]: string }): string => { + const baseDocUrl = baseUrl || defaultDocBaseUrl + const docLanguage = getDocLanguage(locale) + const targetPath = (pathMap !== undefined) ? pathMap[locale] || path : path + return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}` + } } - export default I18NContext diff --git a/web/i18n/language.ts b/web/i18n/language.ts index 1e93884040..a31f9e9c4b 100644 --- a/web/i18n/language.ts +++ b/web/i18n/language.ts @@ -1,5 +1,4 @@ import data from './languages.json' -import { getLocaleOnClient } from '@/i18n/index' export type Item = { value: number | string name: string @@ -50,17 +49,6 @@ export const getDocLanguage = (locale: string) => { return DOC_LANGUAGE[locale] || 'en' } -const officialDocBaseUrl = 'https://docs.dify.ai' -export const useDocLink = (baseUrl?: string): ((path: string, pathMap?: { [index: string]: string }) => string) => { - return (path: string, pathMap?: { [index: string]: string }): string => { - const baseDocUrl = baseUrl || officialDocBaseUrl - const locale = getLocaleOnClient() - const docLanguage = getDocLanguage(locale) - const targetPath = (pathMap !== undefined) ? pathMap[locale] || path : path - return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}` - } -} - const PRICING_PAGE_LANGUAGE: Record = { 'ja-JP': 'jp', }