feat: 优化国际化
This commit is contained in:
parent
debca09f6c
commit
337f0a6d33
|
|
@ -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({
|
|||
<header className="flex items-center justify-between">
|
||||
<h1 className="text-text-color text-4xl font-bold">
|
||||
{characterName}
|
||||
{msg('common_desc')}
|
||||
</h1>
|
||||
<div>
|
||||
<IconFont type="icon-jubao" size={20} />
|
||||
|
|
|
|||
|
|
@ -1,38 +1,4 @@
|
|||
import { useTranslations } from 'next-intl';
|
||||
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,
|
||||
};
|
||||
};
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const useMounted = () => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export default {};
|
||||
|
|
@ -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: '描述',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export default {};
|
||||
Loading…
Reference in New Issue