diff --git a/.vscode/settings.json b/.vscode/settings.json index 2508d1ce820..c674d073382 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,8 +16,8 @@ "i18n-ally.keystyle": "flat", "i18n-ally.sortKeys": true, "i18n-ally.keepFulfilled": false, - "i18n-ally.sourceLanguage": "zh", // 根据此语言文件翻译其他语言文件的变量和内容 - "i18n-ally.displayLanguage": "zh", // 显示语言 + "i18n-ally.sourceLanguage": "zh-CN", // 根据此语言文件翻译其他语言文件的变量和内容 + "i18n-ally.displayLanguage": "zh-CN", // 显示语言 "i18n-ally.namespace": true, "i18n-ally.pathMatcher": "{locale}/{namespaces}.json", "i18n-ally.extract.targetPickingStrategy": "most-similar-by-key", diff --git a/packages/web/hooks/useI18n.ts b/packages/web/hooks/useI18n.ts index b0d6b619cd8..09d83027c54 100644 --- a/packages/web/hooks/useI18n.ts +++ b/packages/web/hooks/useI18n.ts @@ -1,5 +1,6 @@ import Cookies, { CookieAttributes } from 'js-cookie'; import { useTranslation } from 'next-i18next'; +import { LangEnum } from '../../../projects/app/src/web/common/utils/i18n'; const setCookie = (key: string, value: string, options?: CookieAttributes) => { Cookies.set(key, value, options); @@ -13,11 +14,13 @@ const LANG_KEY = 'NEXT_LOCALE'; export const useI18nLng = () => { const { i18n } = useTranslation(); const languageMap: Record = { - zh: 'zh', - 'zh-CN': 'zh', - 'zh-Hans': 'zh', - en: 'en', - 'en-US': 'en' + zh: LangEnum.zh_CN, + 'zh-CN': LangEnum.zh_CN, + 'zh-Hans': LangEnum.zh_CN, + 'zh-HK': LangEnum.zh_CN, + 'zh-TW': LangEnum.zh_TW, + en: LangEnum.en, + 'en-US': LangEnum.en }; const onChangeLng = (lng: string) => { diff --git a/packages/web/i18n/zh/app.json b/packages/web/i18n/zh-CN/app.json similarity index 100% rename from packages/web/i18n/zh/app.json rename to packages/web/i18n/zh-CN/app.json diff --git a/packages/web/i18n/zh/chat.json b/packages/web/i18n/zh-CN/chat.json similarity index 100% rename from packages/web/i18n/zh/chat.json rename to packages/web/i18n/zh-CN/chat.json diff --git a/packages/web/i18n/zh/common.json b/packages/web/i18n/zh-CN/common.json similarity index 100% rename from packages/web/i18n/zh/common.json rename to packages/web/i18n/zh-CN/common.json diff --git a/packages/web/i18n/zh/dataset.json b/packages/web/i18n/zh-CN/dataset.json similarity index 100% rename from packages/web/i18n/zh/dataset.json rename to packages/web/i18n/zh-CN/dataset.json diff --git a/packages/web/i18n/zh/file.json b/packages/web/i18n/zh-CN/file.json similarity index 100% rename from packages/web/i18n/zh/file.json rename to packages/web/i18n/zh-CN/file.json diff --git a/packages/web/i18n/zh/login.json b/packages/web/i18n/zh-CN/login.json similarity index 100% rename from packages/web/i18n/zh/login.json rename to packages/web/i18n/zh-CN/login.json diff --git a/packages/web/i18n/zh/publish.json b/packages/web/i18n/zh-CN/publish.json similarity index 100% rename from packages/web/i18n/zh/publish.json rename to packages/web/i18n/zh-CN/publish.json diff --git a/packages/web/i18n/zh/user.json b/packages/web/i18n/zh-CN/user.json similarity index 100% rename from packages/web/i18n/zh/user.json rename to packages/web/i18n/zh-CN/user.json diff --git a/packages/web/i18n/zh/workflow.json b/packages/web/i18n/zh-CN/workflow.json similarity index 100% rename from packages/web/i18n/zh/workflow.json rename to packages/web/i18n/zh-CN/workflow.json diff --git a/packages/web/i18n/zh_TW/app.json b/packages/web/i18n/zh-TW/app.json similarity index 100% rename from packages/web/i18n/zh_TW/app.json rename to packages/web/i18n/zh-TW/app.json diff --git a/packages/web/i18n/zh_TW/chat.json b/packages/web/i18n/zh-TW/chat.json similarity index 100% rename from packages/web/i18n/zh_TW/chat.json rename to packages/web/i18n/zh-TW/chat.json diff --git a/packages/web/i18n/zh_TW/common.json b/packages/web/i18n/zh-TW/common.json similarity index 100% rename from packages/web/i18n/zh_TW/common.json rename to packages/web/i18n/zh-TW/common.json diff --git a/packages/web/i18n/zh_TW/dataset.json b/packages/web/i18n/zh-TW/dataset.json similarity index 100% rename from packages/web/i18n/zh_TW/dataset.json rename to packages/web/i18n/zh-TW/dataset.json diff --git a/packages/web/i18n/zh_TW/file.json b/packages/web/i18n/zh-TW/file.json similarity index 100% rename from packages/web/i18n/zh_TW/file.json rename to packages/web/i18n/zh-TW/file.json diff --git a/packages/web/i18n/zh_TW/login.json b/packages/web/i18n/zh-TW/login.json similarity index 100% rename from packages/web/i18n/zh_TW/login.json rename to packages/web/i18n/zh-TW/login.json diff --git a/packages/web/i18n/zh_TW/publish.json b/packages/web/i18n/zh-TW/publish.json similarity index 100% rename from packages/web/i18n/zh_TW/publish.json rename to packages/web/i18n/zh-TW/publish.json diff --git a/packages/web/i18n/zh_TW/user.json b/packages/web/i18n/zh-TW/user.json similarity index 100% rename from packages/web/i18n/zh_TW/user.json rename to packages/web/i18n/zh-TW/user.json diff --git a/packages/web/i18n/zh_TW/workflow.json b/packages/web/i18n/zh-TW/workflow.json similarity index 100% rename from packages/web/i18n/zh_TW/workflow.json rename to packages/web/i18n/zh-TW/workflow.json diff --git a/packages/web/types/i18next.d.ts b/packages/web/types/i18next.d.ts index 20a2fcfb3b9..145804a530f 100644 --- a/packages/web/types/i18next.d.ts +++ b/packages/web/types/i18next.d.ts @@ -1,13 +1,13 @@ import 'i18next'; -import common from '../i18n/zh/common.json'; -import dataset from '../i18n/zh/dataset.json'; -import app from '../i18n/zh/app.json'; -import file from '../i18n/zh/file.json'; -import publish from '../i18n/zh/publish.json'; -import workflow from '../i18n/zh/workflow.json'; -import user from '../i18n/zh/user.json'; -import chat from '../i18n/zh/chat.json'; -import login from '../i18n/zh/login.json'; +import common from '../i18n/zh-CN/common.json'; +import dataset from '../i18n/zh-CN/dataset.json'; +import app from '../i18n/zh-CN/app.json'; +import file from '../i18n/zh-CN/file.json'; +import publish from '../i18n/zh-CN/publish.json'; +import workflow from '../i18n/zh-CN/workflow.json'; +import user from '../i18n/zh-CN/user.json'; +import chat from '../i18n/zh-CN/chat.json'; +import login from '../i18n/zh-CN/login.json'; export interface I18nNamespaces { common: typeof common; diff --git a/projects/app/next-i18next.config.js b/projects/app/next-i18next.config.js index dce1cf6e5d9..d16520ce46f 100644 --- a/projects/app/next-i18next.config.js +++ b/projects/app/next-i18next.config.js @@ -5,8 +5,8 @@ module.exports = { i18n: { - defaultLocale: 'zh', - locales: ['en', 'zh', 'zh_TW'], + defaultLocale: 'zh-CN', + locales: ['en', 'zh-CN', 'zh-TW'], localeDetection: false }, localePath: diff --git a/projects/app/src/components/Select/I18nLngSelector.tsx b/projects/app/src/components/Select/I18nLngSelector.tsx index 18e5f17ccfe..7a74c0e1588 100644 --- a/projects/app/src/components/Select/I18nLngSelector.tsx +++ b/projects/app/src/components/Select/I18nLngSelector.tsx @@ -1,5 +1,5 @@ import { langMap } from '@/web/common/utils/i18n'; -import { Avatar, Box, Flex } from '@chakra-ui/react'; +import { Box, Flex } from '@chakra-ui/react'; import MySelect from '@fastgpt/web/components/common/MySelect'; import { useI18nLng } from '@fastgpt/web/hooks/useI18n'; import { useTranslation } from 'next-i18next'; @@ -14,7 +14,7 @@ const I18nLngSelector = () => { return Object.entries(langMap).map(([key, lang]) => ({ label: ( - + {lang.label} ), diff --git a/projects/app/src/web/common/utils/i18n.ts b/projects/app/src/web/common/utils/i18n.ts index 27f2ab75572..0f1493933fd 100644 --- a/projects/app/src/web/common/utils/i18n.ts +++ b/projects/app/src/web/common/utils/i18n.ts @@ -2,18 +2,21 @@ import { I18nNsType } from '@fastgpt/web/types/i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; export enum LangEnum { - 'zh' = 'zh', + 'zh_CN' = 'zh-CN', + 'zh_TW' = 'zh-TW', 'en' = 'en' } export const langMap = { [LangEnum.en]: { label: 'English(US)', - icon: 'common/language/en', avatar: 'common/language/America' }, - [LangEnum.zh]: { + [LangEnum.zh_CN]: { label: '简体中文', - icon: 'common/language/zh', + avatar: 'common/language/China' + }, + [LangEnum.zh_TW]: { + label: '中文(台湾)', avatar: 'common/language/China' } };