From 9574730050e8095f56252d7369db976841ee81cd Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:31:06 +0800 Subject: [PATCH] Feat/i18n restructure (#2529) --- web/.eslintrc.json | 1 + .../[appId]/overview/page.tsx | 3 +- web/app/(commonLayout)/apps/page.tsx | 3 +- .../[datasetId]/layout.tsx | 9 +- .../[datasetId]/settings/page.tsx | 13 +- web/app/(commonLayout)/datasets/Doc.tsx | 5 +- web/app/activate/activateForm.tsx | 8 +- web/app/components/app-sidebar/basic.tsx | 2 +- .../csv-downloader.tsx | 7 +- .../app/annotation/header-opts/index.tsx | 9 +- .../conversation-histroy/history-panel.tsx | 5 +- .../config-voice/param-config-content.tsx | 2 +- .../agent/agent-tools/choose-tool/index.tsx | 5 +- .../agent-tools/setting-built-in-tool.tsx | 4 +- .../chat-group/text-to-speech/index.tsx | 2 +- .../prompt-mode/advanced-mode-waring.tsx | 5 +- .../toolbox/moderation/index.tsx | 4 +- .../moderation/moderation-setting-modal.tsx | 9 +- .../tools/external-data-tool-modal.tsx | 7 +- .../app/overview/customize/index.tsx | 5 +- .../app/overview/settings/index.tsx | 4 +- .../components/billing/pricing/plan-item.tsx | 6 +- .../datasets/create/file-uploader/index.tsx | 5 +- .../datasets/create/step-two/index.tsx | 5 +- .../detail/batch-modal/csv-downloader.tsx | 5 +- .../documents/detail/embedding/index.tsx | 2 +- .../components/datasets/documents/index.tsx | 2 +- web/app/components/develop/doc.tsx | 8 +- .../develop/secret-key/secret-key-modal.tsx | 5 +- web/app/components/explore/category.tsx | 2 +- .../components/header/account-about/index.tsx | 7 +- .../header/account-dropdown/index.tsx | 5 +- .../account-setting/language-page/index.tsx | 4 +- .../account-setting/members-page/index.tsx | 8 +- .../members-page/invite-modal/index.tsx | 4 +- .../model-provider-page/declarations.ts | 16 +- .../model-provider-page/hooks.ts | 3 +- .../components/header/maintenance-notice.tsx | 9 +- web/app/components/i18n.tsx | 2 +- web/app/components/locale-switcher.tsx | 23 -- .../edit-custom-collection-modal/test-api.tsx | 4 +- web/app/components/tools/tool-list/header.tsx | 5 +- web/app/components/tools/tool-list/item.tsx | 6 +- .../components/tools/tool-nav-list/item.tsx | 4 +- web/app/install/installForm.tsx | 2 - web/app/signin/_header.tsx | 4 +- web/app/signin/normalForm.tsx | 7 +- web/app/signin/oneMoreStep.tsx | 4 +- web/context/i18n.ts | 4 +- web/i18n/README.md | 175 ++++++++++++++ web/i18n/README_CN.md | 82 ------- web/i18n/README_EN.md | 81 ------- web/i18n/client.ts | 16 -- .../app-annotation.ts} | 0 .../{lang/app-api.en.ts => en-US/app-api.ts} | 0 .../app-debug.en.ts => en-US/app-debug.ts} | 0 .../{lang/app-log.en.ts => en-US/app-log.ts} | 0 .../app-overview.ts} | 0 web/i18n/{lang/app.en.ts => en-US/app.ts} | 0 .../{lang/billing.en.ts => en-US/billing.ts} | 0 .../{lang/common.en.ts => en-US/common.ts} | 0 .../{lang/custom.en.ts => en-US/custom.ts} | 0 .../dataset-creation.ts} | 0 .../dataset-documents.ts} | 0 .../dataset-hit-testing.ts} | 0 .../dataset-settings.ts} | 0 .../{lang/dataset.en.ts => en-US/dataset.ts} | 0 .../{lang/explore.en.ts => en-US/explore.ts} | 0 .../{lang/layout.en.ts => en-US/layout.ts} | 0 web/i18n/{lang/login.en.ts => en-US/login.ts} | 0 .../{lang/layout.pt.ts => en-US/register.ts} | 0 .../share-app.en.ts => en-US/share-app.ts} | 0 web/i18n/{lang/tools.en.ts => en-US/tools.ts} | 0 web/i18n/i18next-config.ts | 220 +++--------------- web/i18n/i18next-serverside-config.ts | 26 --- web/i18n/index.ts | 18 +- web/{utils => i18n}/language.ts | 181 +++++++------- .../app-annotation.ts} | 0 .../{lang/app-api.pt.ts => pt-BR/app-api.ts} | 0 .../app-debug.pt.ts => pt-BR/app-debug.ts} | 0 .../{lang/app-log.pt.ts => pt-BR/app-log.ts} | 0 .../app-overview.ts} | 0 web/i18n/{lang/app.pt.ts => pt-BR/app.ts} | 0 .../{lang/billing.pt.ts => pt-BR/billing.ts} | 0 .../{lang/common.pt.ts => pt-BR/common.ts} | 0 .../{lang/custom.pt.ts => pt-BR/custom.ts} | 0 .../dataset-creation.ts} | 0 .../dataset-documents.ts} | 0 .../dataset-hit-testing.ts} | 0 .../dataset-settings.ts} | 0 .../{lang/dataset.pt.ts => pt-BR/dataset.ts} | 0 .../{lang/explore.pt.ts => pt-BR/explore.ts} | 0 .../{lang/layout.uk.ts => pt-BR/layout.ts} | 0 web/i18n/{lang/login.pt.ts => pt-BR/login.ts} | 0 .../{lang/layout.zh.ts => pt-BR/register.ts} | 0 .../share-app.pt.ts => pt-BR/share-app.ts} | 0 web/i18n/{lang/tools.pt.ts => pt-BR/tools.ts} | 0 web/i18n/server.ts | 31 ++- .../app-annotation.ts} | 0 .../{lang/app-api.uk.ts => uk-UA/app-api.ts} | 0 .../app-debug.uk.ts => uk-UA/app-debug.ts} | 0 .../{lang/app-log.uk.ts => uk-UA/app-log.ts} | 0 .../app-overview.ts} | 0 web/i18n/{lang/app.uk.ts => uk-UA/app.ts} | 0 .../{lang/billing.uk.ts => uk-UA/billing.ts} | 0 .../{lang/common.uk.ts => uk-UA/common.ts} | 0 .../{lang/custom.uk.ts => uk-UA/custom.ts} | 0 .../dataset-creation.ts} | 0 .../dataset-documents.ts} | 0 .../dataset-hit-testing.ts} | 0 .../dataset-settings.ts} | 0 .../{lang/dataset.uk.ts => uk-UA/dataset.ts} | 0 .../{lang/explore.uk.ts => uk-UA/explore.ts} | 0 .../{lang/register.en.ts => uk-UA/layout.ts} | 0 web/i18n/{lang/login.uk.ts => uk-UA/login.ts} | 0 .../register.pt.ts => uk-UA/register.ts} | 0 .../share-app.uk.ts => uk-UA/share-app.ts} | 0 web/i18n/{lang/tools.uk.ts => uk-UA/tools.ts} | 0 .../app-annotation.ts} | 0 .../app-api.zh.ts => zh-Hans/app-api.ts} | 0 .../app-debug.zh.ts => zh-Hans/app-debug.ts} | 0 .../app-log.zh.ts => zh-Hans/app-log.ts} | 0 .../app-overview.ts} | 0 web/i18n/{lang/app.zh.ts => zh-Hans/app.ts} | 0 .../billing.zh.ts => zh-Hans/billing.ts} | 0 .../{lang/common.zh.ts => zh-Hans/common.ts} | 0 .../{lang/custom.zh.ts => zh-Hans/custom.ts} | 0 .../dataset-creation.ts} | 0 .../dataset-documents.ts} | 0 .../dataset-hit-testing.ts} | 0 .../dataset-settings.ts} | 0 .../dataset.zh.ts => zh-Hans/dataset.ts} | 0 .../explore.zh.ts => zh-Hans/explore.ts} | 0 .../register.uk.ts => zh-Hans/layout.ts} | 0 .../{lang/login.zh.ts => zh-Hans/login.ts} | 0 .../register.zh.ts => zh-Hans/register.ts} | 0 .../share-app.zh.ts => zh-Hans/share-app.ts} | 0 .../{lang/tools.zh.ts => zh-Hans/tools.ts} | 0 web/models/common.ts | 2 +- web/types/app.ts | 2 +- 140 files changed, 448 insertions(+), 659 deletions(-) delete mode 100644 web/app/components/locale-switcher.tsx create mode 100644 web/i18n/README.md delete mode 100644 web/i18n/README_CN.md delete mode 100644 web/i18n/README_EN.md delete mode 100644 web/i18n/client.ts rename web/i18n/{lang/app-annotation.en.ts => en-US/app-annotation.ts} (100%) rename web/i18n/{lang/app-api.en.ts => en-US/app-api.ts} (100%) rename web/i18n/{lang/app-debug.en.ts => en-US/app-debug.ts} (100%) rename web/i18n/{lang/app-log.en.ts => en-US/app-log.ts} (100%) rename web/i18n/{lang/app-overview.en.ts => en-US/app-overview.ts} (100%) rename web/i18n/{lang/app.en.ts => en-US/app.ts} (100%) rename web/i18n/{lang/billing.en.ts => en-US/billing.ts} (100%) rename web/i18n/{lang/common.en.ts => en-US/common.ts} (100%) rename web/i18n/{lang/custom.en.ts => en-US/custom.ts} (100%) rename web/i18n/{lang/dataset-creation.en.ts => en-US/dataset-creation.ts} (100%) rename web/i18n/{lang/dataset-documents.en.ts => en-US/dataset-documents.ts} (100%) rename web/i18n/{lang/dataset-hit-testing.en.ts => en-US/dataset-hit-testing.ts} (100%) rename web/i18n/{lang/dataset-settings.en.ts => en-US/dataset-settings.ts} (100%) rename web/i18n/{lang/dataset.en.ts => en-US/dataset.ts} (100%) rename web/i18n/{lang/explore.en.ts => en-US/explore.ts} (100%) rename web/i18n/{lang/layout.en.ts => en-US/layout.ts} (100%) rename web/i18n/{lang/login.en.ts => en-US/login.ts} (100%) rename web/i18n/{lang/layout.pt.ts => en-US/register.ts} (100%) rename web/i18n/{lang/share-app.en.ts => en-US/share-app.ts} (100%) rename web/i18n/{lang/tools.en.ts => en-US/tools.ts} (100%) delete mode 100644 web/i18n/i18next-serverside-config.ts rename web/{utils => i18n}/language.ts (86%) rename web/i18n/{lang/app-annotation.pt.ts => pt-BR/app-annotation.ts} (100%) rename web/i18n/{lang/app-api.pt.ts => pt-BR/app-api.ts} (100%) rename web/i18n/{lang/app-debug.pt.ts => pt-BR/app-debug.ts} (100%) rename web/i18n/{lang/app-log.pt.ts => pt-BR/app-log.ts} (100%) rename web/i18n/{lang/app-overview.pt.ts => pt-BR/app-overview.ts} (100%) rename web/i18n/{lang/app.pt.ts => pt-BR/app.ts} (100%) rename web/i18n/{lang/billing.pt.ts => pt-BR/billing.ts} (100%) rename web/i18n/{lang/common.pt.ts => pt-BR/common.ts} (100%) rename web/i18n/{lang/custom.pt.ts => pt-BR/custom.ts} (100%) rename web/i18n/{lang/dataset-creation.pt.ts => pt-BR/dataset-creation.ts} (100%) rename web/i18n/{lang/dataset-documents.pt.ts => pt-BR/dataset-documents.ts} (100%) rename web/i18n/{lang/dataset-hit-testing.pt.ts => pt-BR/dataset-hit-testing.ts} (100%) rename web/i18n/{lang/dataset-settings.pt.ts => pt-BR/dataset-settings.ts} (100%) rename web/i18n/{lang/dataset.pt.ts => pt-BR/dataset.ts} (100%) rename web/i18n/{lang/explore.pt.ts => pt-BR/explore.ts} (100%) rename web/i18n/{lang/layout.uk.ts => pt-BR/layout.ts} (100%) rename web/i18n/{lang/login.pt.ts => pt-BR/login.ts} (100%) rename web/i18n/{lang/layout.zh.ts => pt-BR/register.ts} (100%) rename web/i18n/{lang/share-app.pt.ts => pt-BR/share-app.ts} (100%) rename web/i18n/{lang/tools.pt.ts => pt-BR/tools.ts} (100%) rename web/i18n/{lang/app-annotation.uk.ts => uk-UA/app-annotation.ts} (100%) rename web/i18n/{lang/app-api.uk.ts => uk-UA/app-api.ts} (100%) rename web/i18n/{lang/app-debug.uk.ts => uk-UA/app-debug.ts} (100%) rename web/i18n/{lang/app-log.uk.ts => uk-UA/app-log.ts} (100%) rename web/i18n/{lang/app-overview.uk.ts => uk-UA/app-overview.ts} (100%) rename web/i18n/{lang/app.uk.ts => uk-UA/app.ts} (100%) rename web/i18n/{lang/billing.uk.ts => uk-UA/billing.ts} (100%) rename web/i18n/{lang/common.uk.ts => uk-UA/common.ts} (100%) rename web/i18n/{lang/custom.uk.ts => uk-UA/custom.ts} (100%) rename web/i18n/{lang/dataset-creation.uk.ts => uk-UA/dataset-creation.ts} (100%) rename web/i18n/{lang/dataset-documents.uk.ts => uk-UA/dataset-documents.ts} (100%) rename web/i18n/{lang/dataset-hit-testing.uk.ts => uk-UA/dataset-hit-testing.ts} (100%) rename web/i18n/{lang/dataset-settings.uk.ts => uk-UA/dataset-settings.ts} (100%) rename web/i18n/{lang/dataset.uk.ts => uk-UA/dataset.ts} (100%) rename web/i18n/{lang/explore.uk.ts => uk-UA/explore.ts} (100%) rename web/i18n/{lang/register.en.ts => uk-UA/layout.ts} (100%) rename web/i18n/{lang/login.uk.ts => uk-UA/login.ts} (100%) rename web/i18n/{lang/register.pt.ts => uk-UA/register.ts} (100%) rename web/i18n/{lang/share-app.uk.ts => uk-UA/share-app.ts} (100%) rename web/i18n/{lang/tools.uk.ts => uk-UA/tools.ts} (100%) rename web/i18n/{lang/app-annotation.zh.ts => zh-Hans/app-annotation.ts} (100%) rename web/i18n/{lang/app-api.zh.ts => zh-Hans/app-api.ts} (100%) rename web/i18n/{lang/app-debug.zh.ts => zh-Hans/app-debug.ts} (100%) rename web/i18n/{lang/app-log.zh.ts => zh-Hans/app-log.ts} (100%) rename web/i18n/{lang/app-overview.zh.ts => zh-Hans/app-overview.ts} (100%) rename web/i18n/{lang/app.zh.ts => zh-Hans/app.ts} (100%) rename web/i18n/{lang/billing.zh.ts => zh-Hans/billing.ts} (100%) rename web/i18n/{lang/common.zh.ts => zh-Hans/common.ts} (100%) rename web/i18n/{lang/custom.zh.ts => zh-Hans/custom.ts} (100%) rename web/i18n/{lang/dataset-creation.zh.ts => zh-Hans/dataset-creation.ts} (100%) rename web/i18n/{lang/dataset-documents.zh.ts => zh-Hans/dataset-documents.ts} (100%) rename web/i18n/{lang/dataset-hit-testing.zh.ts => zh-Hans/dataset-hit-testing.ts} (100%) rename web/i18n/{lang/dataset-settings.zh.ts => zh-Hans/dataset-settings.ts} (100%) rename web/i18n/{lang/dataset.zh.ts => zh-Hans/dataset.ts} (100%) rename web/i18n/{lang/explore.zh.ts => zh-Hans/explore.ts} (100%) rename web/i18n/{lang/register.uk.ts => zh-Hans/layout.ts} (100%) rename web/i18n/{lang/login.zh.ts => zh-Hans/login.ts} (100%) rename web/i18n/{lang/register.zh.ts => zh-Hans/register.ts} (100%) rename web/i18n/{lang/share-app.zh.ts => zh-Hans/share-app.ts} (100%) rename web/i18n/{lang/tools.zh.ts => zh-Hans/tools.ts} (100%) diff --git a/web/.eslintrc.json b/web/.eslintrc.json index 1ab9727739..53308105b6 100644 --- a/web/.eslintrc.json +++ b/web/.eslintrc.json @@ -8,6 +8,7 @@ "error", "type" ], + "@typescript-eslint/no-var-requires": "off", "no-console": "off", "indent": "off", "@typescript-eslint/indent": [ diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/page.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/page.tsx index 7061bf1253..8f924268f2 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/page.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/page.tsx @@ -1,8 +1,7 @@ import React from 'react' import ChartView from './chartView' import CardView from './cardView' -import { getLocaleOnServer } from '@/i18n/server' -import { useTranslation as translate } from '@/i18n/i18next-serverside-config' +import { getLocaleOnServer, useTranslation as translate } from '@/i18n/server' import ApikeyInfoPanel from '@/app/components/app/overview/apikey-info-panel' export type IDevelopProps = { diff --git a/web/app/(commonLayout)/apps/page.tsx b/web/app/(commonLayout)/apps/page.tsx index 1b54c3c5ad..feb4cb0821 100644 --- a/web/app/(commonLayout)/apps/page.tsx +++ b/web/app/(commonLayout)/apps/page.tsx @@ -1,8 +1,7 @@ import classNames from 'classnames' import style from '../list.module.css' import Apps from './Apps' -import { getLocaleOnServer } from '@/i18n/server' -import { useTranslation as translate } from '@/i18n/i18next-serverside-config' +import { getLocaleOnServer, useTranslation as translate } from '@/i18n/server' const AppList = async () => { const locale = getLocaleOnServer() diff --git a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx index b280e73d74..c93c0761fa 100644 --- a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx +++ b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx @@ -25,7 +25,7 @@ import Link from 'next/link' import s from './style.module.css' import { fetchDatasetDetail, fetchDatasetRelatedApps } from '@/service/datasets' import type { RelatedApp, RelatedAppResponse } from '@/models/datasets' -import { getLocaleOnClient } from '@/i18n/client' +import { getLocaleOnClient } from '@/i18n' import AppSideBar from '@/app/components/app-sidebar' import Divider from '@/app/components/base/divider' import Indicator from '@/app/components/header/indicator' @@ -35,7 +35,7 @@ import FloatPopoverContainer from '@/app/components/base/float-popover-container import DatasetDetailContext from '@/context/dataset-detail' import { DataSourceType } from '@/models/datasets' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' -import { LanguagesSupported, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' export type IAppDetailLayoutProps = { children: React.ReactNode @@ -72,7 +72,7 @@ const LikedItem = ({ const TargetIcon = ({ className }: SVGProps) => { return - + @@ -105,7 +105,6 @@ type IExtraInfoProps = { const ExtraInfo = ({ isMobile, relatedApps }: IExtraInfoProps) => { const locale = getLocaleOnClient() - const language = getModelRuntimeSupported(locale) const [isShowTips, { toggle: toggleTips, set: setShowTips }] = useBoolean(!isMobile) const { t } = useTranslation() @@ -150,7 +149,7 @@ const ExtraInfo = ({ isMobile, relatedApps }: IExtraInfoProps) => { { +const Settings = async () => { const locale = getLocaleOnServer() const { t } = await translate(locale, 'dataset-settings') @@ -19,7 +12,7 @@ const Settings = async ({
{t('title')}
{t('desc')}
-
+ ) } diff --git a/web/app/(commonLayout)/datasets/Doc.tsx b/web/app/(commonLayout)/datasets/Doc.tsx index b1b7b00cf7..a6dd8c23ef 100644 --- a/web/app/(commonLayout)/datasets/Doc.tsx +++ b/web/app/(commonLayout)/datasets/Doc.tsx @@ -5,7 +5,7 @@ import { useContext } from 'use-context-selector' import TemplateEn from './template/template.en.mdx' import TemplateZh from './template/template.zh.mdx' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type DocProps = { apiBaseUrl: string @@ -14,11 +14,10 @@ const Doc: FC = ({ apiBaseUrl, }) => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) return (
{ - language !== LanguagesSupportedUnderscore[1] + locale !== LanguagesSupported[1] ? : } diff --git a/web/app/activate/activateForm.tsx b/web/app/activate/activateForm.tsx index a820a650ea..3cf88ce281 100644 --- a/web/app/activate/activateForm.tsx +++ b/web/app/activate/activateForm.tsx @@ -12,7 +12,7 @@ import Button from '@/app/components/base/button' import { SimpleSelect } from '@/app/components/base/select' import { timezones } from '@/utils/timezone' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported, languages } from '@/utils/language' +import { LanguagesSupported, languages } from '@/i18n/language' import { activateMember, invitationCheck } from '@/service/common' import Toast from '@/app/components/base/toast' import Loading from '@/app/components/base/loading' @@ -42,9 +42,9 @@ const ActivateForm = () => { const [name, setName] = useState('') const [password, setPassword] = useState('') const [timezone, setTimezone] = useState('Asia/Shanghai') - const [language, setLanguage] = useState(getModelRuntimeSupported(locale)) + const [language, setLanguage] = useState(locale) const [showSuccess, setShowSuccess] = useState(false) - const defaultLanguage = useCallback(() => (window.navigator.language.startsWith('zh') ? LanguagesSupportedUnderscore[1] : LanguagesSupportedUnderscore[0]) || LanguagesSupportedUnderscore[0], []) + const defaultLanguage = useCallback(() => (window.navigator.language.startsWith('zh') ? LanguagesSupported[1] : LanguagesSupported[0]) || LanguagesSupported[0], []) const showErrorMessage = useCallback((message: string) => { Toast.notify({ @@ -207,7 +207,7 @@ const ActivateForm = () => { {t('login.license.link')} diff --git a/web/app/components/app-sidebar/basic.tsx b/web/app/components/app-sidebar/basic.tsx index 36bcdd9e7d..46dce55eb8 100644 --- a/web/app/components/app-sidebar/basic.tsx +++ b/web/app/components/app-sidebar/basic.tsx @@ -36,7 +36,7 @@ const WebappSvg = const NotionSvg = - + diff --git a/web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx b/web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx index 37512abf6c..fbbea70612 100644 --- a/web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx +++ b/web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx @@ -8,7 +8,7 @@ import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' const CSV_TEMPLATE_QA_EN = [ ['question', 'answer'], @@ -25,11 +25,10 @@ const CSVDownload: FC = () => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { CSVDownloader, Type } = useCSVDownloader() const getTemplate = () => { - return language !== LanguagesSupportedUnderscore[1] ? CSV_TEMPLATE_QA_EN : CSV_TEMPLATE_QA_CN + return locale !== LanguagesSupported[1] ? CSV_TEMPLATE_QA_EN : CSV_TEMPLATE_QA_CN } return ( @@ -58,7 +57,7 @@ const CSVDownload: FC = () => { diff --git a/web/app/components/app/annotation/header-opts/index.tsx b/web/app/components/app/annotation/header-opts/index.tsx index b5c749bcd7..90b1a9672e 100644 --- a/web/app/components/app/annotation/header-opts/index.tsx +++ b/web/app/components/app/annotation/header-opts/index.tsx @@ -20,7 +20,7 @@ import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows import I18n from '@/context/i18n' import { fetchExportAnnotationList } from '@/service/annotation' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' const CSV_HEADER_QA_EN = ['Question', 'Answer'] const CSV_HEADER_QA_CN = ['问题', '答案'] @@ -40,7 +40,6 @@ const HeaderOptions: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { CSVDownloader, Type } = useCSVDownloader() const [list, setList] = useState([]) @@ -56,7 +55,7 @@ const HeaderOptions: FC = ({ const content = listTransformer(list).join('\n') const file = new Blob([content], { type: 'application/jsonl' }) a.href = URL.createObjectURL(file) - a.download = `annotations-${language}.jsonl` + a.download = `annotations-${locale}.jsonl` a.click() } @@ -110,10 +109,10 @@ const HeaderOptions: FC = ({ > [item.question, item.answer]), ]} > diff --git a/web/app/components/app/configuration/config-prompt/conversation-histroy/history-panel.tsx b/web/app/components/app/configuration/config-prompt/conversation-histroy/history-panel.tsx index bf4b9c9f51..f40bd4b733 100644 --- a/web/app/components/app/configuration/config-prompt/conversation-histroy/history-panel.tsx +++ b/web/app/components/app/configuration/config-prompt/conversation-histroy/history-panel.tsx @@ -7,7 +7,7 @@ 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 I18n from '@/context/i18n' -import { LanguagesSupported, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type Props = { showWarning: boolean @@ -20,7 +20,6 @@ const HistoryPanel: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) return ( = ({ {showWarning && (
{t('appDebug.feature.conversationHistory.tip')} - { const { t } = useTranslation() const pathname = usePathname() diff --git a/web/app/components/app/configuration/config/agent/agent-tools/choose-tool/index.tsx b/web/app/components/app/configuration/config/agent/agent-tools/choose-tool/index.tsx index b5dec18a5b..0b0e0676b7 100644 --- a/web/app/components/app/configuration/config/agent/agent-tools/choose-tool/index.tsx +++ b/web/app/components/app/configuration/config/agent/agent-tools/choose-tool/index.tsx @@ -10,7 +10,7 @@ import Drawer from '@/app/components/base/drawer-plus' import ConfigContext from '@/context/debug-configuration' import type { ModelConfig } from '@/models/debug' import I18n from '@/context/i18n' -import { getModelRuntimeSupported } from '@/utils/language' + type Props = { show: boolean onHide: () => void @@ -24,7 +24,6 @@ const ChooseTool: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { modelConfig, setModelConfig, @@ -60,7 +59,7 @@ const ChooseTool: FC = ({ provider_type: collection.type, provider_name: collection.name, tool_name: tool.name, - tool_label: tool.label[language], + tool_label: tool.label[locale], tool_parameters: parameters, enabled: true, }) diff --git a/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx b/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx index e1c99e0432..98f454bd20 100644 --- a/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx +++ b/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx @@ -13,7 +13,7 @@ import I18n from '@/context/i18n' import Button from '@/app/components/base/button' import Loading from '@/app/components/base/loading' import { DiagonalDividingLine } from '@/app/components/base/icons/src/public/common' -import { getModelRuntimeSupported } from '@/utils/language' +import { getLanguage } from '@/i18n/language' type Props = { collection: Collection toolName: string @@ -32,7 +32,7 @@ const SettingBuiltInTool: FC = ({ onSave, }) => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const language = getLanguage(locale) const { t } = useTranslation() const [isLoading, setIsLoading] = useState(true) diff --git a/web/app/components/app/configuration/features/chat-group/text-to-speech/index.tsx b/web/app/components/app/configuration/features/chat-group/text-to-speech/index.tsx index 596122e57d..6bd40547ca 100644 --- a/web/app/components/app/configuration/features/chat-group/text-to-speech/index.tsx +++ b/web/app/components/app/configuration/features/chat-group/text-to-speech/index.tsx @@ -7,7 +7,7 @@ import { usePathname } from 'next/navigation' import Panel from '@/app/components/app/configuration/base/feature-panel' import { Speaker } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices' import ConfigContext from '@/context/debug-configuration' -import { languages } from '@/utils/language' +import { languages } from '@/i18n/language' import { fetchAppVoices } from '@/service/apps' import AudioBtn from '@/app/components/base/audio-btn' diff --git a/web/app/components/app/configuration/prompt-mode/advanced-mode-waring.tsx b/web/app/components/app/configuration/prompt-mode/advanced-mode-waring.tsx index 0011b7054a..759a15213d 100644 --- a/web/app/components/app/configuration/prompt-mode/advanced-mode-waring.tsx +++ b/web/app/components/app/configuration/prompt-mode/advanced-mode-waring.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import I18n from '@/context/i18n' import { FlipBackward } from '@/app/components/base/icons/src/vender/line/arrows' -import { LanguagesSupported, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type Props = { onReturnToSimpleMode: () => void } @@ -15,7 +15,6 @@ const AdvancedModeWarning: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const [show, setShow] = React.useState(true) if (!show) return null @@ -27,7 +26,7 @@ const AdvancedModeWarning: FC = ({ {t('appDebug.promptMode.advancedWarning.description')} {t('appDebug.promptMode.advancedWarning.learnMore')} diff --git a/web/app/components/app/configuration/toolbox/moderation/index.tsx b/web/app/components/app/configuration/toolbox/moderation/index.tsx index 7731d9ebd2..9eb14e98d2 100644 --- a/web/app/components/app/configuration/toolbox/moderation/index.tsx +++ b/web/app/components/app/configuration/toolbox/moderation/index.tsx @@ -7,12 +7,10 @@ import { useModalContext } from '@/context/modal-context' import ConfigContext from '@/context/debug-configuration' import { fetchCodeBasedExtensionList } from '@/service/common' import I18n from '@/context/i18n' -import { getModelRuntimeSupported } from '@/utils/language' const Moderation = () => { const { t } = useTranslation() const { setShowModerationSettingModal } = useModalContext() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { moderationConfig, setModerationConfig, @@ -39,7 +37,7 @@ const Moderation = () => { else if (moderationConfig.type === 'api') prefix = t('common.apiBasedExtension.selector.title') else - prefix = codeBasedExtensionList?.data.find(item => item.name === moderationConfig.type)?.label[language] || '' + prefix = codeBasedExtensionList?.data.find(item => item.name === moderationConfig.type)?.label[locale] || '' if (moderationConfig.config?.inputs_config?.enabled && moderationConfig.config?.outputs_config?.enabled) suffix = t('appDebug.feature.moderation.allEnabled') diff --git a/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx b/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx index a1b8d7deda..5bc52e5564 100644 --- a/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx +++ b/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx @@ -17,7 +17,7 @@ import { } from '@/service/common' import type { CodeBasedExtensionItem } from '@/models/common' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' import { InfoCircle } from '@/app/components/base/icons/src/vender/line/general' import { useModalContext } from '@/context/modal-context' import { CustomConfigurationStatusEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' @@ -44,7 +44,6 @@ const ModerationSettingModal: FC = ({ const { t } = useTranslation() const { notify } = useToastContext() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { data: modelProviders, isLoading, mutate } = useSWR('/workspaces/current/model-providers', fetchModelProviders) const [localeData, setLocaleData] = useState(data) const { setShowAccountSettingModal } = useModalContext() @@ -200,12 +199,12 @@ const ModerationSettingModal: FC = ({ } if (localeData.type === 'keywords' && !localeData.config.keywords) { - notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: language !== LanguagesSupportedUnderscore[1] ? 'keywords' : '关键词' }) }) + notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'keywords' : '关键词' }) }) return } if (localeData.type === 'api' && !localeData.config.api_based_extension_id) { - notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: language !== LanguagesSupportedUnderscore[1] ? 'API Extension' : 'API 扩展' }) }) + notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展' }) }) return } @@ -214,7 +213,7 @@ const ModerationSettingModal: FC = ({ if (!localeData.config?.[currentProvider.form_schema[i].variable] && currentProvider.form_schema[i].required) { notify({ type: 'error', - message: t('appDebug.errorMessage.valueOfVarRequired', { key: language !== LanguagesSupportedUnderscore[1] ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), + message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), }) return } diff --git a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx index d52b66b65c..6a6e355956 100644 --- a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx +++ b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx @@ -12,7 +12,7 @@ import { BookOpen01 } from '@/app/components/base/icons/src/vender/line/educatio import { fetchCodeBasedExtensionList } from '@/service/common' import { SimpleSelect } from '@/app/components/base/select' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' import type { CodeBasedExtensionItem, ExternalDataTool, @@ -41,7 +41,6 @@ const ExternalDataToolModal: FC = ({ const { t } = useTranslation() const { notify } = useToastContext() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const [localeData, setLocaleData] = useState(data.type ? data : { ...data, type: 'api' }) const [showEmojiPicker, setShowEmojiPicker] = useState(false) const { data: codeBasedExtensionList } = useSWR( @@ -157,7 +156,7 @@ const ExternalDataToolModal: FC = ({ } if (localeData.type === 'api' && !localeData.config?.api_based_extension_id) { - notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: language !== LanguagesSupportedUnderscore[1] ? 'API Extension' : 'API 扩展' }) }) + notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展' }) }) return } @@ -166,7 +165,7 @@ const ExternalDataToolModal: FC = ({ if (!localeData.config?.[currentProvider.form_schema[i].variable] && currentProvider.form_schema[i].required) { notify({ type: 'error', - message: t('appDebug.errorMessage.valueOfVarRequired', { key: language !== LanguagesSupportedUnderscore[1] ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), + message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), }) return } diff --git a/web/app/components/app/overview/customize/index.tsx b/web/app/components/app/overview/customize/index.tsx index 826a85aae5..5baf6dd4d3 100644 --- a/web/app/components/app/overview/customize/index.tsx +++ b/web/app/components/app/overview/customize/index.tsx @@ -9,7 +9,7 @@ import I18n from '@/context/i18n' import Button from '@/app/components/base/button' import Modal from '@/app/components/base/modal' import Tag from '@/app/components/base/tag' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type IShareLinkProps = { isShow: boolean @@ -44,7 +44,6 @@ const CustomizeModal: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const isChatApp = mode === 'chat' return = ({ className='w-36 mt-2' onClick={() => window.open( - `https://docs.dify.ai/${language !== LanguagesSupportedUnderscore[1] + `https://docs.dify.ai/${locale !== LanguagesSupported[1] ? 'user-guide/launching-dify-apps/developing-with-apis' : `v/${locale.toLowerCase()}/guides/application-publishing/developing-with-apis` }`, diff --git a/web/app/components/app/overview/settings/index.tsx b/web/app/components/app/overview/settings/index.tsx index 6926dace3c..026ba6ae10 100644 --- a/web/app/components/app/overview/settings/index.tsx +++ b/web/app/components/app/overview/settings/index.tsx @@ -13,7 +13,7 @@ import type { AppDetailResponse } from '@/models/app' import type { Language } from '@/types/app' import EmojiPicker from '@/app/components/base/emoji-picker' -import { languages } from '@/utils/language' +import { languages } from '@/i18n/language' export type ISettingsModalProps = { appInfo: AppDetailResponse @@ -122,7 +122,7 @@ const SettingsModal: FC = ({ />
{t(`${prefixSettings}.language`)}
item.supported)} defaultValue={language} onSelect={item => setLanguage(item.value as Language)} /> diff --git a/web/app/components/billing/pricing/plan-item.tsx b/web/app/components/billing/pricing/plan-item.tsx index 823e4308d1..9e694041b3 100644 --- a/web/app/components/billing/pricing/plan-item.tsx +++ b/web/app/components/billing/pricing/plan-item.tsx @@ -12,7 +12,7 @@ import { PlanRange } from './select-plan-range' import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general' import { useAppContext } from '@/context/app-context' import { fetchSubscriptionUrls } from '@/service/billing' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' import I18n from '@/context/i18n' type Props = { @@ -73,8 +73,8 @@ const PlanItem: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) - const isZh = language === LanguagesSupportedUnderscore[1] + + const isZh = locale === LanguagesSupported[1] const [loading, setLoading] = React.useState(false) const i18nPrefix = `billing.plans.${plan}` const isFreePlan = plan === Plan.sandbox diff --git a/web/app/components/datasets/create/file-uploader/index.tsx b/web/app/components/datasets/create/file-uploader/index.tsx index 2ad766e800..dfedffbbdc 100644 --- a/web/app/components/datasets/create/file-uploader/index.tsx +++ b/web/app/components/datasets/create/file-uploader/index.tsx @@ -12,7 +12,7 @@ import { upload } from '@/service/base' import { fetchFileUploadConfig } from '@/service/common' import { fetchSupportFileTypes } from '@/service/datasets' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' const FILES_NUMBER_LIMIT = 20 @@ -36,7 +36,6 @@ const FileUploader = ({ const { t } = useTranslation() const { notify } = useContext(ToastContext) const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const [dragging, setDragging] = useState(false) const dropRef = useRef(null) const dragRef = useRef(null) @@ -77,7 +76,7 @@ const FileUploader = ({ res = res.map(item => item.toLowerCase()) res = res.filter((item, index, self) => self.indexOf(item) === index) - return res.map(item => item.toUpperCase()).join(language !== LanguagesSupportedUnderscore[1] ? ', ' : '、 ') + return res.map(item => item.toUpperCase()).join(locale !== LanguagesSupported[1] ? ', ' : '、 ') })() const ACCEPTS = supportTypes.map((ext: string) => `.${ext}`) const fileUploadConfig = useMemo(() => fileUploadConfigResponse ?? { diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index 7a2c61e28e..4688d7afee 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -42,7 +42,7 @@ import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import Tooltip from '@/app/components/base/tooltip' import TooltipPlus from '@/app/components/base/tooltip-plus' import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type ValueOf = T[keyof T] type StepTwoProps = { @@ -89,7 +89,6 @@ const StepTwo = ({ }: StepTwoProps) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const media = useBreakpoints() const isMobile = media === MediaType.mobile @@ -114,7 +113,7 @@ const StepTwo = ({ const [docForm, setDocForm] = useState( (datasetId && documentDetail) ? documentDetail.doc_form : DocForm.TEXT, ) - const [docLanguage, setDocLanguage] = useState(language !== LanguagesSupportedUnderscore[1] ? 'English' : 'Chinese') + const [docLanguage, setDocLanguage] = useState(locale !== LanguagesSupported[1] ? 'English' : 'Chinese') const [QATipHide, setQATipHide] = useState(false) const [previewSwitched, setPreviewSwitched] = useState(false) const [showPreview, { setTrue: setShowPreview, setFalse: hidePreview }] = useBoolean() diff --git a/web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx b/web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx index d44f36303f..36216aa7c8 100644 --- a/web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx +++ b/web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx @@ -9,7 +9,7 @@ import { useContext } from 'use-context-selector' import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general' import { DocForm } from '@/models/datasets' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' const CSV_TEMPLATE_QA_EN = [ ['question', 'answer'], @@ -35,11 +35,10 @@ const CSV_TEMPLATE_CN = [ const CSVDownload: FC<{ docForm: DocForm }> = ({ docForm }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { CSVDownloader, Type } = useCSVDownloader() const getTemplate = () => { - if (language === LanguagesSupportedUnderscore[1]) { + if (locale === LanguagesSupported[1]) { if (docForm === DocForm.QA) return CSV_TEMPLATE_QA_CN return CSV_TEMPLATE_CN diff --git a/web/app/components/datasets/documents/detail/embedding/index.tsx b/web/app/components/datasets/documents/detail/embedding/index.tsx index a1432fc5d5..3c152f3f99 100644 --- a/web/app/components/datasets/documents/detail/embedding/index.tsx +++ b/web/app/components/datasets/documents/detail/embedding/index.tsx @@ -35,7 +35,7 @@ type Props = { const StopIcon = ({ className }: SVGProps) => { return - + diff --git a/web/app/components/datasets/documents/index.tsx b/web/app/components/datasets/documents/index.tsx index 7a05bec341..13f8fd8f9b 100644 --- a/web/app/components/datasets/documents/index.tsx +++ b/web/app/components/datasets/documents/index.tsx @@ -38,7 +38,7 @@ const ThreeDotsIcon = ({ className }: React.SVGProps) => { const NotionIcon = ({ className }: React.SVGProps) => { return - + diff --git a/web/app/components/develop/doc.tsx b/web/app/components/develop/doc.tsx index 698849c8fc..41ed2e9b3a 100644 --- a/web/app/components/develop/doc.tsx +++ b/web/app/components/develop/doc.tsx @@ -5,7 +5,7 @@ import TemplateZh from './template/template.zh.mdx' import TemplateChatEn from './template/template_chat.en.mdx' import TemplateChatZh from './template/template_chat.zh.mdx' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' type IDocProps = { appDetail: any @@ -13,7 +13,7 @@ type IDocProps = { const Doc = ({ appDetail }: IDocProps) => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const variables = appDetail?.model_config?.configs?.prompt_variables || [] const inputs = variables.reduce((res: any, variable: any) => { res[variable.key] = variable.name || '' @@ -24,10 +24,10 @@ const Doc = ({ appDetail }: IDocProps) => {
{appDetail?.mode === 'completion' ? ( - language !== LanguagesSupportedUnderscore[1] ? : + locale !== LanguagesSupported[1] ? : ) : ( - language !== LanguagesSupportedUnderscore[1] ? : + locale !== LanguagesSupported[1] ? : )}
) diff --git a/web/app/components/develop/secret-key/secret-key-modal.tsx b/web/app/components/develop/secret-key/secret-key-modal.tsx index 852c91cf37..510399e187 100644 --- a/web/app/components/develop/secret-key/secret-key-modal.tsx +++ b/web/app/components/develop/secret-key/secret-key-modal.tsx @@ -27,7 +27,7 @@ import Tooltip from '@/app/components/base/tooltip' import Loading from '@/app/components/base/loading' import Confirm from '@/app/components/base/confirm' import I18n from '@/context/i18n' -import { LanguagesSupported, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' import { useAppContext } from '@/context/app-context' type ISecretKeyModalProps = { @@ -56,7 +56,6 @@ const SecretKeyModal = ({ const [delKeyID, setDelKeyId] = useState('') const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) // const [isCopied, setIsCopied] = useState(false) const [copyValue, setCopyValue] = useState('') @@ -102,7 +101,7 @@ const SecretKeyModal = ({ } const formatDate = (timestamp: string) => { - if (language === LanguagesSupported[0]) + if (locale === LanguagesSupported[0]) return new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' }).format((+timestamp) * 1000) else return new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit' }).format((+timestamp) * 1000) diff --git a/web/app/components/explore/category.tsx b/web/app/components/explore/category.tsx index dc5dbf1b7a..a2a11973b5 100644 --- a/web/app/components/explore/category.tsx +++ b/web/app/components/explore/category.tsx @@ -3,7 +3,7 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import cn from 'classnames' -import exploreI18n from '@/i18n/lang/explore.en' +import exploreI18n from '@/i18n/en-US/explore' import type { AppCategory } from '@/models/explore' const categoryI18n = exploreI18n.category diff --git a/web/app/components/header/account-about/index.tsx b/web/app/components/header/account-about/index.tsx index 9ec99c6320..6ab0541b07 100644 --- a/web/app/components/header/account-about/index.tsx +++ b/web/app/components/header/account-about/index.tsx @@ -9,7 +9,7 @@ import { XClose } from '@/app/components/base/icons/src/vender/line/general' import type { LangGeniusVersionResponse } from '@/models/common' import { IS_CE_EDITION } from '@/config' import I18n from '@/context/i18n' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' import LogoSite from '@/app/components/base/logo/logo-site' type IAccountSettingProps = { @@ -26,7 +26,6 @@ export default function AccountAbout({ }: IAccountSettingProps) { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const isLatest = langeniusVersionInfo.current_version === langeniusVersionInfo.latest_version return ( @@ -49,8 +48,8 @@ export default function AccountAbout({ IS_CE_EDITION ? Open Source License : <> - Privacy Policy, - Terms of Service + Privacy Policy, + Terms of Service }
diff --git a/web/app/components/header/account-dropdown/index.tsx b/web/app/components/header/account-dropdown/index.tsx index 739d5aabe4..da9d3b5dc6 100644 --- a/web/app/components/header/account-dropdown/index.tsx +++ b/web/app/components/header/account-dropdown/index.tsx @@ -16,7 +16,7 @@ import { useAppContext } from '@/context/app-context' import { ArrowUpRight, ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' import { LogOut01 } from '@/app/components/base/icons/src/vender/line/general' import { useModalContext } from '@/context/modal-context' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' export type IAppSelecotr = { isMobile: boolean } @@ -30,7 +30,6 @@ export default function AppSelector({ isMobile }: IAppSelecotr) { const [aboutVisible, setAboutVisible] = useState(false) const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const { t } = useTranslation() const { userProfile, langeniusVersionInfo } = useAppContext() const { setShowAccountSettingModal } = useModalContext() @@ -123,7 +122,7 @@ export default function AppSelector({ isMobile }: IAppSelecotr) {
{t('common.userProfile.helpCenter')}
diff --git a/web/app/components/header/account-setting/language-page/index.tsx b/web/app/components/header/account-setting/language-page/index.tsx index 0c5f5f4357..7f30113867 100644 --- a/web/app/components/header/account-setting/language-page/index.tsx +++ b/web/app/components/header/account-setting/language-page/index.tsx @@ -10,7 +10,7 @@ import { updateUserProfile } from '@/service/common' import { ToastContext } from '@/app/components/base/toast' import I18n from '@/context/i18n' import { timezones } from '@/utils/timezone' -import { languages } from '@/utils/language' +import { languages } from '@/i18n/language' const titleClassName = ` mb-2 text-sm font-medium text-gray-900 @@ -53,7 +53,7 @@ export default function LanguagePage() {
{t('common.language.displayLanguage')}
item.supported)} onSelect={item => handleSelect('language', item)} disabled={editing} /> diff --git a/web/app/components/header/account-setting/members-page/index.tsx b/web/app/components/header/account-setting/members-page/index.tsx index 0bd9c6cf4a..2c10bc24fa 100644 --- a/web/app/components/header/account-setting/members-page/index.tsx +++ b/web/app/components/header/account-setting/members-page/index.tsx @@ -20,7 +20,7 @@ import { useProviderContext } from '@/context/provider-context' import { Plan } from '@/app/components/billing/type' import UpgradeBtn from '@/app/components/billing/upgrade-btn' import { NUM_INFINITE } from '@/app/components/billing/config' -import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language' +import { LanguagesSupported } from '@/i18n/language' dayjs.extend(relativeTime) const MembersPage = () => { @@ -31,7 +31,7 @@ const MembersPage = () => { normal: t('common.members.normal'), } const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const { userProfile, currentWorkspace, isCurrentWorkspaceManager } = useAppContext() const { data, mutate } = useSWR({ url: '/workspaces/current/members' }, fetchMembers) const [inviteModalVisible, setInviteModalVisible] = useState(false) @@ -55,7 +55,7 @@ const MembersPage = () => { {isNotUnlimitedMemberPlan ? (
-
{t('billing.plansCommon.member')}{language !== LanguagesSupportedUnderscore[1] && accounts.length > 1 && 's'}
+
{t('billing.plansCommon.member')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}
{accounts.length}
/
{plan.total.teamMembers === NUM_INFINITE ? t('billing.plansCommon.unlimited') : plan.total.teamMembers}
@@ -64,7 +64,7 @@ const MembersPage = () => { : (
{accounts.length}
-
{t('billing.plansCommon.memberAfter')}{language !== LanguagesSupportedUnderscore[1] && accounts.length > 1 && 's'}
+
{t('billing.plansCommon.memberAfter')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}
)}
diff --git a/web/app/components/header/account-setting/members-page/invite-modal/index.tsx b/web/app/components/header/account-setting/members-page/invite-modal/index.tsx index 5d7af96034..3b8cb8c699 100644 --- a/web/app/components/header/account-setting/members-page/invite-modal/index.tsx +++ b/web/app/components/header/account-setting/members-page/invite-modal/index.tsx @@ -15,7 +15,6 @@ import { emailRegex } from '@/config' import { ToastContext } from '@/app/components/base/toast' import type { InvitationResult } from '@/models/common' import I18n from '@/context/i18n' -import { getModelRuntimeSupported } from '@/utils/language' import 'react-multi-email/dist/style.css' type IInviteModalProps = { @@ -32,7 +31,6 @@ const InviteModal = ({ const { notify } = useContext(ToastContext) const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const InvitingRoles = useMemo(() => [ { @@ -51,7 +49,7 @@ const InviteModal = ({ try { const { result, invitation_results } = await inviteMember({ url: '/workspaces/current/members/invite-email', - body: { emails, role: role.name, language }, + body: { emails, role: role.name, language: locale }, }) if (result === 'success') { diff --git a/web/app/components/header/account-setting/model-provider-page/declarations.ts b/web/app/components/header/account-setting/model-provider-page/declarations.ts index 7a683c8df8..da8c69b69d 100644 --- a/web/app/components/header/account-setting/model-provider-page/declarations.ts +++ b/web/app/components/header/account-setting/model-provider-page/declarations.ts @@ -1,8 +1,8 @@ export type FormValue = Record export type TypeWithI18N = { - 'en_US': T - 'zh_Hans': T + 'en-US': T + 'zh-Hans': T [key: string]: T } @@ -67,16 +67,16 @@ export enum ModelStatusEnum { export const MODEL_STATUS_TEXT: { [k: string]: TypeWithI18N } = { 'no-configure': { - en_US: 'No Configure', - zh_Hans: '未配置凭据', + 'en-US': 'No Configure', + 'zh-Hans': '未配置凭据', }, 'quota-exceeded': { - en_US: 'Quota Exceeded', - zh_Hans: '额度不足', + 'en-US': 'Quota Exceeded', + 'zh-Hans': '额度不足', }, 'no-permission': { - en_US: 'No Permission', - zh_Hans: '无使用权限', + 'en-US': 'No Permission', + 'zh-Hans': '无使用权限', }, } diff --git a/web/app/components/header/account-setting/model-provider-page/hooks.ts b/web/app/components/header/account-setting/model-provider-page/hooks.ts index 57975f2f87..3b5bdbb682 100644 --- a/web/app/components/header/account-setting/model-provider-page/hooks.ts +++ b/web/app/components/header/account-setting/model-provider-page/hooks.ts @@ -16,7 +16,6 @@ import { ConfigurateMethodEnum, ModelTypeEnum, } from './declarations' -import { getModelRuntimeSupported } from '@/utils/language' import I18n from '@/context/i18n' import { fetchDefaultModal, @@ -59,7 +58,7 @@ export const useSystemDefaultModelAndModelList: UseDefaultModelAndModelList = ( export const useLanguage = () => { const { locale } = useContext(I18n) - return getModelRuntimeSupported(locale) + return locale.replace('-', '_') } export const useProviderCrenditialsFormSchemasValue = ( diff --git a/web/app/components/header/maintenance-notice.tsx b/web/app/components/header/maintenance-notice.tsx index 88e65ef526..a7f3faab8e 100644 --- a/web/app/components/header/maintenance-notice.tsx +++ b/web/app/components/header/maintenance-notice.tsx @@ -2,11 +2,10 @@ import { useState } from 'react' import { useContext } from 'use-context-selector' import I18n from '@/context/i18n' import { X } from '@/app/components/base/icons/src/vender/line/general' -import { NOTICE_I18N, getModelRuntimeSupported } from '@/utils/language' +import { NOTICE_I18N } from '@/i18n/language' const MaintenanceNotice = () => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) const [showNotice, setShowNotice] = useState(localStorage.getItem('hide-maintenance-notice') !== '1') const handleJumpNotice = () => { @@ -26,11 +25,11 @@ const MaintenanceNotice = () => { return (
-
{titleByLocale[language]}
+
{titleByLocale[locale]}
{ (NOTICE_I18N.href && NOTICE_I18N.href !== '#') - ?
{descByLocale[language]}
- :
{descByLocale[language]}
+ ?
{descByLocale[locale]}
+ :
{descByLocale[locale]}
}
diff --git a/web/app/components/i18n.tsx b/web/app/components/i18n.tsx index 4166449e76..7fe1df23e0 100644 --- a/web/app/components/i18n.tsx +++ b/web/app/components/i18n.tsx @@ -5,7 +5,7 @@ import React, { useEffect } from 'react' import { changeLanguage } from '@/i18n/i18next-config' import I18NContext from '@/context/i18n' import type { Locale } from '@/i18n' -import { setLocaleOnClient } from '@/i18n/client' +import { setLocaleOnClient } from '@/i18n' export type II18nProps = { locale: Locale diff --git a/web/app/components/locale-switcher.tsx b/web/app/components/locale-switcher.tsx deleted file mode 100644 index 018b3f907f..0000000000 --- a/web/app/components/locale-switcher.tsx +++ /dev/null @@ -1,23 +0,0 @@ -'use client' - -import { i18n } from '@/i18n' -import { setLocaleOnClient } from '@/i18n/client' - -const LocaleSwitcher = () => { - return ( -
-

Locale switcher:

-
    - {i18n.locales.map((locale) => { - return ( -
  • -
    setLocaleOnClient(locale)}>{locale}
    -
  • - ) - })} -
-
- ) -} - -export default LocaleSwitcher diff --git a/web/app/components/tools/edit-custom-collection-modal/test-api.tsx b/web/app/components/tools/edit-custom-collection-modal/test-api.tsx index a2e3c454d4..b1a494317e 100644 --- a/web/app/components/tools/edit-custom-collection-modal/test-api.tsx +++ b/web/app/components/tools/edit-custom-collection-modal/test-api.tsx @@ -10,7 +10,7 @@ import Button from '@/app/components/base/button' import Drawer from '@/app/components/base/drawer-plus' import I18n from '@/context/i18n' import { testAPIAvailable } from '@/service/tools' -import { getModelRuntimeSupported } from '@/utils/language' +import { getLanguage } from '@/i18n/language' type Props = { customCollection: CustomCollectionBackend @@ -27,7 +27,7 @@ const TestApi: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const language = getLanguage(locale) const [credentialsModalShow, setCredentialsModalShow] = useState(false) const [tempCredential, setTempCredential] = React.useState(customCollection.credentials) const [result, setResult] = useState('') diff --git a/web/app/components/tools/tool-list/header.tsx b/web/app/components/tools/tool-list/header.tsx index bb3907b8b8..5a243a0a2b 100644 --- a/web/app/components/tools/tool-list/header.tsx +++ b/web/app/components/tools/tool-list/header.tsx @@ -8,8 +8,7 @@ import type { Collection } from '../types' import { CollectionType, LOC } from '../types' import { Settings01 } from '../../base/icons/src/vender/line/general' import I18n from '@/context/i18n' -import { getModelRuntimeSupported } from '@/utils/language' - +import { getLanguage } from '@/i18n/language' type Props = { icon: JSX.Element collection: Collection @@ -26,7 +25,7 @@ const Header: FC = ({ onShowEditCustomCollection, }) => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const language = getLanguage(locale) const { t } = useTranslation() const isInToolsPage = loc === LOC.tools const isInDebugPage = !isInToolsPage diff --git a/web/app/components/tools/tool-list/item.tsx b/web/app/components/tools/tool-list/item.tsx index f4437f065a..c4e856e11a 100644 --- a/web/app/components/tools/tool-list/item.tsx +++ b/web/app/components/tools/tool-list/item.tsx @@ -10,8 +10,7 @@ import { CollectionType } from '../types' import TooltipPlus from '../../base/tooltip-plus' import I18n from '@/context/i18n' import SettingBuiltInTool from '@/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool' -import { getModelRuntimeSupported } from '@/utils/language' - +import { getLanguage } from '@/i18n/language' type Props = { collection: Collection icon: JSX.Element @@ -33,7 +32,8 @@ const Item: FC = ({ }) => { const { t } = useTranslation() const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const language = getLanguage(locale) + const isBuiltIn = collection.type === CollectionType.builtIn const canShowDetail = !isBuiltIn || (isBuiltIn && isInToolsPage) const [showDetail, setShowDetail] = useState(false) diff --git a/web/app/components/tools/tool-nav-list/item.tsx b/web/app/components/tools/tool-nav-list/item.tsx index 5e32503d18..2d3606d13e 100644 --- a/web/app/components/tools/tool-nav-list/item.tsx +++ b/web/app/components/tools/tool-nav-list/item.tsx @@ -6,7 +6,7 @@ import cn from 'classnames' import AppIcon from '../../base/app-icon' import type { Collection } from '@/app/components/tools/types' import I18n from '@/context/i18n' -import { getModelRuntimeSupported } from '@/utils/language' +import { getLanguage } from '@/i18n/language' type Props = { isCurrent: boolean @@ -20,7 +20,7 @@ const Item: FC = ({ onClick, }) => { const { locale } = useContext(I18n) - const language = getModelRuntimeSupported(locale) + const language = getLanguage(locale) return (
{ const { t } = useTranslation() - // const { locale } = useContext(I18n) - // const language = getModelRuntimeSupported(locale) const router = useRouter() const [email, setEmail] = React.useState('') diff --git a/web/app/signin/_header.tsx b/web/app/signin/_header.tsx index 1aec9720a5..7180a66817 100644 --- a/web/app/signin/_header.tsx +++ b/web/app/signin/_header.tsx @@ -2,7 +2,7 @@ import React from 'react' import { useContext } from 'use-context-selector' import Select from '@/app/components/base/select/locale' -import { languages } from '@/utils/language' +import { languages } from '@/i18n/language' import { type Locale } from '@/i18n' import I18n from '@/context/i18n' import LogoSite from '@/app/components/base/logo/logo-site' @@ -17,7 +17,7 @@ const Header = () => {