将国际化文本模板替代函数直接放到使用的地方

This commit is contained in:
david_bai
2025-06-07 13:56:57 +08:00
parent 7018b1d5dc
commit 21bfb1762a
5 changed files with 74 additions and 73 deletions
+38 -40
View File
@@ -1,34 +1,32 @@
"use client";
import ClipboardApp from "@/components/ClipboardApp";
import { cn } from "@/lib/utils";
import SystemDiagram from "@/components/web/SystemDiagram";
import FAQSection from "@/components/web/FAQSection";
import HowItWorks from "@/components/web/HowItWorks";
import YouTubePlayer from "@/components/common/YouTubePlayer";
import KeyFeatures from "@/components/web/KeyFeatures";
import type { Messages } from "@/types/messages";
import ClipboardApp from '@/components/ClipboardApp'
import { cn } from "@/lib/utils"
import SystemDiagram from '@/components/web/SystemDiagram'
import FAQSection from '@/components/web/FAQSection'
import HowItWorks from '@/components/web/HowItWorks'
import YouTubePlayer from '@/components/common/YouTubePlayer';
import KeyFeatures from '@/components/web/KeyFeatures'
import type { Messages } from '@/types/messages';
interface PageContentProps {
messages: Messages;
lang: string;
lang:string;
}
export default function HomeClient({ messages, lang }: PageContentProps) {
const youtube_videoId = lang === "zh" ? "I0RLCpcbUXs" : "ypt-po_R2Ds";
const bilibili_videoId = lang === "zh" ? "BV1knrjYZEfn" : "BV1yErjYFEV7";
export default function HomeClient({ messages,lang }: PageContentProps) {
const youtube_videoId = lang==="zh"?"I0RLCpcbUXs":"ypt-po_R2Ds";
const bilibili_videoId = lang==="zh"?"BV1knrjYZEfn":"BV1yErjYFEV7";
return (
<main className="container mx-auto px-4 py-8">
{/* Hero Section */}
<h1 className="text-4xl font-bold mb-2 text-center">
{messages.text.home.h1}
</h1>
<p className="text-xl mb-4 text-center">{messages.text.home.h1P}</p>
<p className="text-xl mb-4 text-center">
{messages.text.home.h1P}
</p>
{/* App Section */}
<section
id="clipboard-app"
className="py-12"
aria-label="File Transfer Application"
>
<section id="clipboard-app" className="py-12" aria-label="File Transfer Application">
<div className="container mx-auto px-4">
{/* sr-only--screen-only:视觉不可见 */}
<h2 className={cn("sr-only", "text-3xl font-bold mb-8 text-center")}>
@@ -46,47 +44,47 @@ export default function HomeClient({ messages, lang }: PageContentProps) {
{messages.text.home.h2P_demo}
</p>
<YouTubePlayer videoId={youtube_videoId} />
<div className="mt-4 text-center">
<p className="mb-3 text-gray-700">{messages.text.home.watch_tips}</p>
<a
className="flex justify-center gap-4 text-blue-500 hover:underline transition-colors"
href={`https://www.youtube.com/watch?v=${youtube_videoId}`}
target="_blank"
rel="noopener noreferrer"
>
<p className="mb-3 text-gray-700">
{messages.text.home.watch_tips}
</p>
<a className="flex justify-center gap-4 text-blue-500 hover:underline transition-colors"
href={`https://www.youtube.com/watch?v=${youtube_videoId}`}
target="_blank"
rel="noopener noreferrer"
>
{messages.text.home.youtube_tips}
</a>
<a
className="flex justify-center gap-4 text-blue-500 hover:underline transition-colors"
href={`https://www.bilibili.com/video/${bilibili_videoId}`}
target="_blank"
rel="noopener noreferrer"
>
<a className="flex justify-center gap-4 text-blue-500 hover:underline transition-colors"
href={`https://www.bilibili.com/video/${bilibili_videoId}`}
target="_blank"
rel="noopener noreferrer"
>
{messages.text.home.bilibili_tips}
</a>
</div>
</section>
{/* How It Works Section */}
<section aria-label="How It Works">
<HowItWorks messages={messages} />
<HowItWorks messages={messages}/>
</section>
{/* System Architecture Section */}
<section aria-label="System Architecture">
<SystemDiagram messages={messages} />
<SystemDiagram messages={messages}/>
</section>
{/* Key Features */}
<section aria-label="Key Features">
<KeyFeatures messages={messages} />
<KeyFeatures messages={messages}/>
</section>
{/* FAQ Section */}
<section aria-label="Frequently Asked Questions">
<FAQSection
<FAQSection
messages={messages}
isMainPage
isMainPage
titleClassName="text-2xl md:text-3xl" // 可选:在首页使用稍小的字号
/>
/>
</section>
</main>
);
}
)
}
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from "react";
import { Button } from "@/components/ui/button";
import { Download, Trash2 } from "lucide-react";
import { Tooltip } from "@/components/Tooltip";
import TransferProgress from "@/components/ClipboardApp/TransferProgress";
import TransferProgress from "./TransferProgress";
import { formatFileSize, generateFileId } from "@/lib/fileUtils";
import { AutoPopupDialog } from "@/components/common/AutoPopupDialog";
import { FileMeta, CustomFile, Progress } from "@/lib/types/file";
@@ -10,7 +10,23 @@ import FileTransferButton from "./FileTransferButton";
import { getDictionary } from "@/lib/dictionary";
import { useLocale } from "@/hooks/useLocale";
import type { Messages } from "@/types/messages";
import { formatFolderTips, formatFolderDis } from "@/utils/formatMessage";
function formatFolderDis(
template: string,
num: number,
size: string
) {
return template.replace('{num}', num.toString()).replace('{size}', size);
}
function formatFolderTips(
template: string,
name: string,
num: number,
size: string
) {
return template.replace('{name}', name).replace('{num}', num.toString()).replace('{size}', size);
}
interface FileListDisplayProps {
mode: "sender" | "receiver";
@@ -16,7 +16,7 @@ declare module "@/components/ui/input" {
directory?: string | boolean;
}
}
import {formatFileChosen } from '@/utils/formatMessage';
import { getDictionary } from '@/lib/dictionary';
import { useLocale } from '@/hooks/useLocale';
import type { Messages } from '@/types/messages';
@@ -58,6 +58,16 @@ const traverseFileTree = async (item: FileSystemEntry, path = ''): Promise<Custo
}
});
};
function formatFileChosen(
template: string,
fileNum: number,
folderNum: number
) {
return template.replace('{fileNum}', fileNum.toString())
.replace('{folderNum}', folderNum.toString());
}
interface FileUploadHandlerProps {
onFilePicked: (files: CustomFile[]) => void;
}
+7 -1
View File
@@ -1,11 +1,17 @@
import { useState, useEffect, useCallback, useMemo } from "react";
import { fetchRoom, createRoom, checkRoom } from "@/app/config/api";
import { debounce } from "lodash";
import { format_peopleMsg } from "@/utils/formatMessage";
import type { Messages } from "@/types/messages";
import type WebRTC_Initiator from "@/lib/webrtc_Initiator";
import type WebRTC_Recipient from "@/lib/webrtc_Recipient";
function format_peopleMsg(
template: string,
peerCount: number
) {
return template.replace('{peerCount}', peerCount.toString());
}
interface UseRoomManagerProps {
messages: Messages | null;
putMessageInMs: (
-29
View File
@@ -1,29 +0,0 @@
export function formatFileChosen(
template: string,
fileNum: number,
folderNum: number
) {
return template.replace('{fileNum}', fileNum.toString())
.replace('{folderNum}', folderNum.toString());
}
export function formatFolderTips(
template: string,
name: string,
num: number,
size: string
) {
return template.replace('{name}', name).replace('{num}', num.toString()).replace('{size}', size);
}
export function formatFolderDis(
template: string,
num: number,
size: string
) {
return template.replace('{num}', num.toString()).replace('{size}', size);
}
export function format_peopleMsg(
template: string,
peerCount: number
) {
return template.replace('{peerCount}', peerCount.toString());
}