From e7a428d8f0ecc094132971afc7fce7f071f58070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Tue, 3 Feb 2026 17:18:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20=E6=9B=B4=E6=96=B0=E4=B8=AD?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E7=BF=BB=E8=AF=91=E5=8F=8A=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在Workshop和Line模块中添加新的翻译字段 - 修复页面中硬编码的文本,改为使用翻译 - 更新产品线和车间展示的英文翻译内容 - 为卡片组件添加locale属性传递 --- app/[locale]/line/[slug]/page.tsx | 6 +- app/[locale]/line/page.tsx | 4 +- app/[locale]/workshop/[slug]/page.tsx | 4 +- app/[locale]/workshop/page.tsx | 2 +- components/home/index.tsx | 2 +- i18n/messages/en.json | 88 ++++++++++++++++----------- i18n/messages/zh.json | 3 +- 7 files changed, 65 insertions(+), 44 deletions(-) diff --git a/app/[locale]/line/[slug]/page.tsx b/app/[locale]/line/[slug]/page.tsx index 324acf2..1a3e5a9 100644 --- a/app/[locale]/line/[slug]/page.tsx +++ b/app/[locale]/line/[slug]/page.tsx @@ -4,6 +4,7 @@ import { constructMetadata } from "@/lib/metadata"; import { Line } from "@/types/line"; import { Metadata } from "next"; import { Locale } from "next-intl"; +import { getTranslations } from "next-intl/server"; // 强制静态渲染 export const dynamic = "force-static"; @@ -48,6 +49,7 @@ export async function generateMetadata({ export default async function ProductDetailPage({ params }: { params: Params }) { const { locale, slug } = await params; const line = await getLine(locale, slug); + const t = await getTranslations({ locale, namespace: "Line" }); if (!line) return
404 - 产线不存在
; @@ -82,7 +84,7 @@ export default async function ProductDetailPage({ params }: { params: Params }) {line.images && line.images.length > 0 && (

- 产品图片 + {t("productImages")}

{line.images.map((imgUrl, index) => ( @@ -103,7 +105,7 @@ export default async function ProductDetailPage({ params }: { params: Params }) {line.properties && line.properties.length > 0 && (

- 产品参数 + {t("productProperties")}

    {line.properties.map((prop, index) => ( diff --git a/app/[locale]/line/page.tsx b/app/[locale]/line/page.tsx index 082d918..080220b 100644 --- a/app/[locale]/line/page.tsx +++ b/app/[locale]/line/page.tsx @@ -110,7 +110,7 @@ export default async function Page({ }) { const { locale } = await params; // 获取翻译(确保服务端/客户端一致) - const t = await getTranslations({ locale, namespace: "Workshop" }); + const t = await getTranslations({ locale, namespace: "Line" }); // 获取产品线数据(顶层 await,Server Component 原生支持) const products: Line[] = await getLines(locale); @@ -129,7 +129,7 @@ export default async function Page({ {products.map((product) => { // 用稳定的 key(优先用唯一标识,如 id;无 id 则用 title+locale 避免 index 导致的问题) const stableKey = `${product.title}-${product.locale}`; - return ; + return ; })}
) : ( diff --git a/app/[locale]/workshop/[slug]/page.tsx b/app/[locale]/workshop/[slug]/page.tsx index 00660d5..bc482e5 100644 --- a/app/[locale]/workshop/[slug]/page.tsx +++ b/app/[locale]/workshop/[slug]/page.tsx @@ -4,6 +4,7 @@ import { getWorkShop, getWorkShops } from "@/lib/workshop"; import { WorkShop } from "@/types/workShop"; import { Metadata } from "next"; import { Locale } from "next-intl"; +import { getTranslations } from "next-intl/server"; // 固定 Params 类型为普通对象(Next.js 原生传参无异步) type Params = { @@ -45,6 +46,7 @@ export async function generateMetadata({ export default async function WorkshopDetailPage({ params }: { params: Params }) { const { locale, slug } = await params; const workShop = await getWorkShop(locale, slug); + const t = await getTranslations({ locale, namespace: "Workshop" }); if (!workShop) return null; @@ -78,7 +80,7 @@ export default async function WorkshopDetailPage({ params }: { params: Params }) {workShop.images?.length > 0 && (

- 车间图片 + {t("pageImages")}

{workShop.images.map((img, index) => { diff --git a/app/[locale]/workshop/page.tsx b/app/[locale]/workshop/page.tsx index ca9f49e..6855eea 100644 --- a/app/[locale]/workshop/page.tsx +++ b/app/[locale]/workshop/page.tsx @@ -93,7 +93,7 @@ export default async function Page({ params }: { params: Params }) { {workShops.length > 0 ? ( workShops.map((workshop) => { const stableKey = `${workshop.title}-${workshop.locale}`; - return ; + return ; }) ) : ( diff --git a/components/home/index.tsx b/components/home/index.tsx index 974ceb1..305b3aa 100644 --- a/components/home/index.tsx +++ b/components/home/index.tsx @@ -14,7 +14,7 @@ export default function HomeComponent() { {/* 轮播图区域, 先用一张图片占位, 宽度100%, 盖度100vh */} {t("carousel")} {/* 公司介绍 - 左右布局 */} -
+
{/* 左边视频(图片占位) */}