From 337f0a6d335f34b5ccdc5e82b5e0b0f3774c11dd Mon Sep 17 00:00:00 2001 From: liuyonghe0111 <1763195287@qq.com> Date: Thu, 6 Nov 2025 14:44:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[id]/(detail)/components/BasicInfo.tsx | 4 --- src/hooks/index.ts | 36 +------------------ .../MainLayout/components/NavRoutes.tsx | 12 +++---- src/locales/en.ts | 17 +++++---- src/locales/en/character.json | 1 + src/locales/en/character.ts | 1 - src/locales/zh.ts | 17 +++++---- src/locales/zh/character.json | 1 + src/locales/zh/character.ts | 1 - 9 files changed, 31 insertions(+), 59 deletions(-) create mode 100644 src/locales/en/character.json delete mode 100644 src/locales/en/character.ts create mode 100644 src/locales/zh/character.json delete mode 100644 src/locales/zh/character.ts diff --git a/src/app/(main)/character/[id]/(detail)/components/BasicInfo.tsx b/src/app/(main)/character/[id]/(detail)/components/BasicInfo.tsx index 262b629..6958f5c 100644 --- a/src/app/(main)/character/[id]/(detail)/components/BasicInfo.tsx +++ b/src/app/(main)/character/[id]/(detail)/components/BasicInfo.tsx @@ -4,7 +4,6 @@ import { RightArrowIcon } from '@/assets/chatacter'; import IconFont from '@/components/ui/iconFont'; import ChatButton from './ChatButton'; import Tags from '@/components/ui/Tags'; -import { useTranslations } from 'next-intl'; type CharacterBasicInfoProps = { characterId: string; @@ -15,8 +14,6 @@ export default function CharacterBasicInfo({ characterId, characterDetail, }: CharacterBasicInfoProps) { - const msg = useTranslations(); - if (!characterDetail) { return null; } @@ -44,7 +41,6 @@ export default function CharacterBasicInfo({

{characterName} - {msg('common_desc')}

diff --git a/src/hooks/index.ts b/src/hooks/index.ts index e3f1369..05370de 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,38 +1,4 @@ -import { useTranslations } from 'next-intl'; -import { useCallback, useEffect, useState } from 'react'; - -type TranslatorFunction = ReturnType; -type TranslationValues = Parameters[1]; - -export const useMsg = (prefix: string) => { - const msg = useTranslations(); - - const pageMsg = useCallback( - ( - key: string, - values?: TranslationValues - ): ReturnType => { - return msg(`${prefix}_${key}`, values); - }, - [msg, prefix] - ); - - const cmnMsg = useCallback( - ( - key: string, - values?: TranslationValues - ): ReturnType => { - return msg(`common_${key}`, values); - }, - [msg] - ); - - return { - pageMsg, - cmnMsg, - msg, - }; -}; +import { useEffect, useState } from 'react'; export const useMounted = () => { const [mounted, setMounted] = useState(false); diff --git a/src/layouts/MainLayout/components/NavRoutes.tsx b/src/layouts/MainLayout/components/NavRoutes.tsx index b3116e7..ed9f740 100644 --- a/src/layouts/MainLayout/components/NavRoutes.tsx +++ b/src/layouts/MainLayout/components/NavRoutes.tsx @@ -1,36 +1,36 @@ 'use client'; import React from 'react'; -import { useMsg } from '@/hooks'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { cn } from '@/lib'; import IconFont from '@/components/ui/iconFont'; +import { useTranslations } from 'next-intl'; const NavRoutes = React.memo(() => { - const { pageMsg } = useMsg('menu'); const pathname = usePathname(); + const t = useTranslations('menu'); const routes = [ { path: '/novel', icon: 'icon-novel', - label: pageMsg('novel'), + label: t('novel'), }, { path: '/video', icon: 'icon-video', - label: pageMsg('video'), + label: t('video'), }, { path: '/character', icon: 'icon-character', - label: pageMsg('character'), + label: t('character'), }, { path: '/record', icon: 'icon-record', - label: pageMsg('record'), + label: t('record'), }, ]; diff --git a/src/locales/en.ts b/src/locales/en.ts index 2448490..ccc9e6e 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -1,8 +1,13 @@ +import character from './en/character.json'; export default { - menu_novel: 'Novels', - menu_video: 'Video Comics', - menu_character: 'Characters', - menu_record: 'Record', - - common_desc: 'Description', + character: character, + menu: { + novel: 'Novels', + video: 'Video Comics', + character: 'Characters', + record: 'Record', + }, + common: { + desc: 'Description', + }, }; diff --git a/src/locales/en/character.json b/src/locales/en/character.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/locales/en/character.json @@ -0,0 +1 @@ +{} diff --git a/src/locales/en/character.ts b/src/locales/en/character.ts deleted file mode 100644 index ff8b4c5..0000000 --- a/src/locales/en/character.ts +++ /dev/null @@ -1 +0,0 @@ -export default {}; diff --git a/src/locales/zh.ts b/src/locales/zh.ts index 9512a4b..1305587 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -1,8 +1,13 @@ +import character from './zh/character.json'; export default { - menu_novel: '小说', - menu_video: '视频', - menu_character: '角色', - menu_record: '记录', - - common_desc: '描述', + character: character, + menu: { + novel: '小说', + video: '视频', + character: '角色', + record: '记录', + }, + common: { + desc: '描述', + }, }; diff --git a/src/locales/zh/character.json b/src/locales/zh/character.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/locales/zh/character.json @@ -0,0 +1 @@ +{} diff --git a/src/locales/zh/character.ts b/src/locales/zh/character.ts deleted file mode 100644 index ff8b4c5..0000000 --- a/src/locales/zh/character.ts +++ /dev/null @@ -1 +0,0 @@ -export default {};