From 443dc8370ee08a917abe55d29457d9fdb5dedddc Mon Sep 17 00:00:00 2001 From: Caihaohan Date: Mon, 29 Dec 2025 20:46:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AE=8C=E5=96=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=AF=A6=E6=83=85=E4=B8=8E=E4=BE=A7=E8=BE=B9=E6=A0=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=9B=BD=E9=99=85=E5=8C=96=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 ProjectDetail 和 ProjectSidebar 组件中的硬编码文本替换为国际化翻译键,提升中英文支持一致性。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/components/project/ProjectDetail.tsx | 11 +++-- src/components/project/ProjectSidebar.tsx | 55 +++++++++++++---------- src/messages/en.json | 20 ++++++++- src/messages/zh.json | 20 ++++++++- 4 files changed, 77 insertions(+), 29 deletions(-) diff --git a/src/components/project/ProjectDetail.tsx b/src/components/project/ProjectDetail.tsx index 1e834f7..ab305ef 100644 --- a/src/components/project/ProjectDetail.tsx +++ b/src/components/project/ProjectDetail.tsx @@ -1,4 +1,5 @@ import Link from 'next/link' +import { getTranslations } from 'next-intl/server' import { MarkdownContent } from './MarkdownContent' import { ShareButtons } from './ShareButtons' @@ -46,6 +47,8 @@ function formatDate(date: Date | string, locale: string): string { } export async function ProjectDetail({ project, locale }: ProjectDetailProps) { + const t = await getTranslations('project') + const displayName = locale === 'en' && project.nameEn ? project.nameEn : project.name const displayDescription = locale === 'en' && project.descriptionEn ? project.descriptionEn : project.description @@ -84,7 +87,7 @@ export async function ProjectDetail({ project, locale }: ProjectDetailProps) { |
code - Open Source + {t('openSource')}
@@ -114,7 +117,7 @@ export async function ProjectDetail({ project, locale }: ProjectDetailProps) { smart_toy -

Project Preview

+

{t('projectPreview')}

)} @@ -133,8 +136,8 @@ export async function ProjectDetail({ project, locale }: ProjectDetailProps) { {/* Installation section if GitHub link exists */} {project.links.some((l) => l.type === 'GITHUB') && ( <> -

Getting Started

-

To install this project, clone the repository and install dependencies:

+

{t('gettingStarted')}

+

{t('installInstructions')}

               {`git clone ${
                 project.links.find((l) => l.type === 'GITHUB')?.url || 'https://github.com/example/project'
diff --git a/src/components/project/ProjectSidebar.tsx b/src/components/project/ProjectSidebar.tsx
index 5981804..47dac43 100644
--- a/src/components/project/ProjectSidebar.tsx
+++ b/src/components/project/ProjectSidebar.tsx
@@ -1,4 +1,5 @@
 import Link from 'next/link'
+import { getTranslations } from 'next-intl/server'
 
 interface ProjectSidebarProps {
   project: {
@@ -16,23 +17,24 @@ interface ProjectSidebarProps {
   locale: string
 }
 
-// Helper function to get icon and label for link type
-function getLinkInfo(type: string): { icon: string; label: string } {
+// Helper function to get icon for link type
+function getLinkIcon(type: string): string {
   switch (type.toUpperCase()) {
     case 'WEBSITE':
-      return { icon: 'language', label: 'Official Website' }
+      return 'language'
     case 'GITHUB':
-      return { icon: 'code', label: 'GitHub Repo' }
+      return 'code'
     case 'HUGGINGFACE':
-      return { icon: 'model_training', label: 'Hugging Face' }
+      return 'model_training'
     case 'PAPER':
-      return { icon: 'description', label: 'Paper' }
+      return 'description'
     default:
-      return { icon: 'link', label: 'External Link' }
+      return 'link'
   }
 }
 
-export function ProjectSidebar({ project, locale }: ProjectSidebarProps) {
+export async function ProjectSidebar({ project, locale }: ProjectSidebarProps) {
+  const t = await getTranslations('project')
   const displayName = locale === 'en' && project.nameEn ? project.nameEn : project.name
 
   return (
@@ -41,11 +43,18 @@ export function ProjectSidebar({ project, locale }: ProjectSidebarProps) {
       {project.links.length > 0 && (
         

- Project Links + {t('projectLinks')}

{project.links.map((link) => { - const { icon, label } = getLinkInfo(link.type) + const icon = getLinkIcon(link.type) + const labelMap: Record = { + WEBSITE: t('officialWebsite'), + GITHUB: t('githubRepo'), + HUGGINGFACE: t('huggingface'), + PAPER: t('paper'), + } + const label = labelMap[link.type] || t('externalLinks') return (
- License + {t('license')} MIT
- Pricing + {t('pricing')} Free
- Status + {t('status')} Active
- Type - Open Source + {t('type')} + {t('openSource')}
@@ -98,13 +107,13 @@ export function ProjectSidebar({ project, locale }: ProjectSidebarProps) {
rocket_launch
-

Build Your Own Agent?

-

Start using our API to build custom agents in minutes.

+

{t('buildYourOwnAgent')}

+

{t('buildAgentDesc')}

- Get Started Now + {t('getStartedNow')}
@@ -113,7 +122,7 @@ export function ProjectSidebar({ project, locale }: ProjectSidebarProps) { {locale === 'en' && (

- On this page + {t('onThisPage')}

diff --git a/src/messages/en.json b/src/messages/en.json index d73e3e6..359c75c 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -29,7 +29,25 @@ "submitYourProject": "Submit Your Project", "submitProjectTitle": "Submit Your Project", "submitProjectDescription": "Have an AI tool worth sharing? Add it to Agent Park.", - "submitNow": "SUBMIT NOW" + "submitNow": "SUBMIT NOW", + "projectLinks": "Project Links", + "officialWebsite": "Official Website", + "githubRepo": "GitHub Repo", + "license": "License", + "pricing": "Pricing", + "status": "Status", + "type": "Type", + "openSource": "Open Source", + "projectPreview": "Project Preview", + "gettingStarted": "Getting Started", + "installInstructions": "To install this project, clone the repository and install dependencies:", + "buildYourOwnAgent": "Build Your Own Agent?", + "buildAgentDesc": "Start using our API to build custom agents in minutes.", + "getStartedNow": "Get Started Now", + "onThisPage": "On this page", + "overview": "Overview", + "keyFeatures": "Key Features", + "useCases": "Use Cases" }, "navigation": { "home": "Home", diff --git a/src/messages/zh.json b/src/messages/zh.json index 8e62449..06c1b0a 100644 --- a/src/messages/zh.json +++ b/src/messages/zh.json @@ -29,7 +29,25 @@ "submitYourProject": "提交你的项目", "submitProjectTitle": "提交你的项目", "submitProjectDescription": "有值得分享的 AI 工具吗?将其添加到 Agent Park。", - "submitNow": "立即提交" + "submitNow": "立即提交", + "projectLinks": "项目链接", + "officialWebsite": "官方网站", + "githubRepo": "GitHub 仓库", + "license": "许可证", + "pricing": "定价", + "status": "状态", + "type": "类型", + "openSource": "开源", + "projectPreview": "项目预览", + "gettingStarted": "快速开始", + "installInstructions": "要安装此项目,请克隆仓库并安装依赖:", + "buildYourOwnAgent": "构建你自己的 Agent?", + "buildAgentDesc": "开始使用我们的 API,在几分钟内构建自定义 Agent。", + "getStartedNow": "立即开始", + "onThisPage": "本页内容", + "overview": "概述", + "keyFeatures": "核心功能", + "useCases": "使用场景" }, "navigation": { "home": "首页",