feat: 优化国际化

This commit is contained in:
liuyonghe0111 2025-11-06 14:44:29 +08:00
parent debca09f6c
commit 337f0a6d33
9 changed files with 31 additions and 59 deletions

View File

@ -4,7 +4,6 @@ import { RightArrowIcon } from '@/assets/chatacter';
import IconFont from '@/components/ui/iconFont'; import IconFont from '@/components/ui/iconFont';
import ChatButton from './ChatButton'; import ChatButton from './ChatButton';
import Tags from '@/components/ui/Tags'; import Tags from '@/components/ui/Tags';
import { useTranslations } from 'next-intl';
type CharacterBasicInfoProps = { type CharacterBasicInfoProps = {
characterId: string; characterId: string;
@ -15,8 +14,6 @@ export default function CharacterBasicInfo({
characterId, characterId,
characterDetail, characterDetail,
}: CharacterBasicInfoProps) { }: CharacterBasicInfoProps) {
const msg = useTranslations();
if (!characterDetail) { if (!characterDetail) {
return null; return null;
} }
@ -44,7 +41,6 @@ export default function CharacterBasicInfo({
<header className="flex items-center justify-between"> <header className="flex items-center justify-between">
<h1 className="text-text-color text-4xl font-bold"> <h1 className="text-text-color text-4xl font-bold">
{characterName} {characterName}
{msg('common_desc')}
</h1> </h1>
<div> <div>
<IconFont type="icon-jubao" size={20} /> <IconFont type="icon-jubao" size={20} />

View File

@ -1,38 +1,4 @@
import { useTranslations } from 'next-intl'; import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
type TranslatorFunction = ReturnType<typeof useTranslations>;
type TranslationValues = Parameters<TranslatorFunction>[1];
export const useMsg = (prefix: string) => {
const msg = useTranslations();
const pageMsg = useCallback(
(
key: string,
values?: TranslationValues
): ReturnType<TranslatorFunction> => {
return msg(`${prefix}_${key}`, values);
},
[msg, prefix]
);
const cmnMsg = useCallback(
(
key: string,
values?: TranslationValues
): ReturnType<TranslatorFunction> => {
return msg(`common_${key}`, values);
},
[msg]
);
return {
pageMsg,
cmnMsg,
msg,
};
};
export const useMounted = () => { export const useMounted = () => {
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);

View File

@ -1,36 +1,36 @@
'use client'; 'use client';
import React from 'react'; import React from 'react';
import { useMsg } from '@/hooks';
import Link from 'next/link'; import Link from 'next/link';
import { usePathname } from 'next/navigation'; import { usePathname } from 'next/navigation';
import { cn } from '@/lib'; import { cn } from '@/lib';
import IconFont from '@/components/ui/iconFont'; import IconFont from '@/components/ui/iconFont';
import { useTranslations } from 'next-intl';
const NavRoutes = React.memo(() => { const NavRoutes = React.memo(() => {
const { pageMsg } = useMsg('menu');
const pathname = usePathname(); const pathname = usePathname();
const t = useTranslations('menu');
const routes = [ const routes = [
{ {
path: '/novel', path: '/novel',
icon: 'icon-novel', icon: 'icon-novel',
label: pageMsg('novel'), label: t('novel'),
}, },
{ {
path: '/video', path: '/video',
icon: 'icon-video', icon: 'icon-video',
label: pageMsg('video'), label: t('video'),
}, },
{ {
path: '/character', path: '/character',
icon: 'icon-character', icon: 'icon-character',
label: pageMsg('character'), label: t('character'),
}, },
{ {
path: '/record', path: '/record',
icon: 'icon-record', icon: 'icon-record',
label: pageMsg('record'), label: t('record'),
}, },
]; ];

View File

@ -1,8 +1,13 @@
import character from './en/character.json';
export default { export default {
menu_novel: 'Novels', character: character,
menu_video: 'Video Comics', menu: {
menu_character: 'Characters', novel: 'Novels',
menu_record: 'Record', video: 'Video Comics',
character: 'Characters',
common_desc: 'Description', record: 'Record',
},
common: {
desc: 'Description',
},
}; };

View File

@ -0,0 +1 @@
{}

View File

@ -1 +0,0 @@
export default {};

View File

@ -1,8 +1,13 @@
import character from './zh/character.json';
export default { export default {
menu_novel: '小说', character: character,
menu_video: '视频', menu: {
menu_character: '角色', novel: '小说',
menu_record: '记录', video: '视频',
character: '角色',
common_desc: '描述', record: '记录',
},
common: {
desc: '描述',
},
}; };

View File

@ -0,0 +1 @@
{}

View File

@ -1 +0,0 @@
export default {};