Skip to content

Let's use AI to Earn!

导航翻译

daoyian7a3c281a387b
diff --git a/src/app/i18n/locales/en/route.json b/src/app/i18n/locales/en/route.json
new file mode 100644
index 00000000..b6f73aba
--- /dev/null
+++ b/src/app/i18n/locales/en/route.json
@@ -0,0 +1,7 @@
+{
+ "home": "Home",
+ "accounts": "Accounts",
+ "publish": "Publish",
+ "hotContent": "Hot Content",
+ "hotContentNew": "Hot Content New"
+}
\ No newline at end of file
diff --git a/src/app/i18n/locales/zh-CN/route.json b/src/app/i18n/locales/zh-CN/route.json
new file mode 100644
index 00000000..bba6bf38
--- /dev/null
+++ b/src/app/i18n/locales/zh-CN/route.json
@@ -0,0 +1,7 @@
+{
+ "home": "首页",
+ "accounts": "账户",
+ "publish": "发布",
+ "hotContent": "热门内容",
+ "hotContentNew": "热门内容新"
+}
\ No newline at end of file
diff --git a/src/app/i18n/settings.ts b/src/app/i18n/settings.ts
index c4b7a6fc..c7a6e0b9 100644
--- a/src/app/i18n/settings.ts
+++ b/src/app/i18n/settings.ts
@@ -7,7 +7,7 @@ export const cookieName = "i18next";
export function getOptions(
lng = fallbackLng,
- ns: string | string[] = defaultNS,
+ ns: string | string[] = [defaultNS, "route"],
) {
return {
// debug: true,
diff --git a/src/app/layout/layoutNav.tsx b/src/app/layout/layoutNav.tsx
index 2fa08f4e..2d5111af 100644
--- a/src/app/layout/layoutNav.tsx
+++ b/src/app/layout/layoutNav.tsx
@@ -12,6 +12,7 @@ import Image from "next/image";
import React, { useEffect, useRef, useState } from "react";
import { Drawer, Menu } from "antd";
import { useRouter, useSelectedLayoutSegments } from "next/navigation";
+import { useTransClient } from "@/app/i18n/client";
/**
*
@@ -19,16 +20,17 @@ import { useRouter, useSelectedLayoutSegments } from "next/navigation";
* @param iconLoca 0=上,1=右
*/
function getNameTag(child: IRouterDataItem, iconLoca: number = 1) {
+ const { t } = useTransClient("route");
const path = child.path || "/";
return (
<>
{!child.children ? (
<Link href={path || "/"} target={path[0] === "/" ? "_self" : "_blank"}>
- {child.name}
+ {t(child.translationKey)}
</Link>
) : (
<span>
- {child.name}
+ {t(child.translationKey)}
{child.children &&
(iconLoca === 0 ? <UpOutlined /> : <RightOutlined />)}
</span>
@@ -207,6 +209,12 @@ function NavPC() {
function NavPE() {
const [open, setOpen] = useState(false);
const router = useRouter();
+ const { t } = useTransClient("route");
+
+ const translatedMenuItems = peRouterData?.map(item => ({
+ ...item,
+ label: t(item.key as string)
+ }));
return (
<div className={styles.layoutNavPE}>
@@ -214,7 +222,7 @@ function NavPE() {
<MenuFoldOutlined />
</div>
<Drawer
- title="导航"
+ title={t("navigation")}
placement="right"
onClose={() => setOpen(false)}
width="85%"
@@ -229,7 +237,7 @@ function NavPE() {
}}
style={{ width: "100%" }}
mode="inline"
- items={peRouterData!}
+ items={translatedMenuItems}
/>
</Drawer>
</div>
diff --git a/src/app/layout/routerData.ts b/src/app/layout/routerData.ts
index ab9e2fdb..86e860d3 100644
--- a/src/app/layout/routerData.ts
+++ b/src/app/layout/routerData.ts
@@ -4,7 +4,8 @@ import { MenuItemType } from "antd/es/menu/interface";
export interface IRouterDataItem {
// 导航标题
name: string;
-
+ // 翻译键
+ translationKey: string;
// 跳转链接
path?: string;
// icon
@@ -18,25 +19,29 @@ export interface IRouterDataItem {
export const routerData: IRouterDataItem[] = [
{
name: "首页",
+ translationKey: "home",
path: "/",
},
{
name: "账户",
+ translationKey: "accounts",
path: "/accounts",
},
{
name: "发布",
+ translationKey: "publish",
path: "/publish",
},
{
name: "热门内容",
+ translationKey: "hotContent",
path: "/hot-content",
},
{
name: "热门内容新",
+ translationKey: "hotContentNew",
path: "/hot-content-new",
},
-
];
const recursion = (