refactor: update network tool components for improved user experience
- Translated UI text in DNS, Ping, TCPing, and Speed Test components from Chinese to English for better accessibility. - Enhanced user prompts and labels for clarity, including error messages and button texts. - Updated comments in the code to reflect the changes in language and improve code readability.
This commit is contained in:
@@ -38,14 +38,14 @@ const Tool: FC = () => {
|
||||
|
||||
const ping = async () => {
|
||||
if (!url.trim()) {
|
||||
toast.error("请输入 URL");
|
||||
toast.error("Please enter a URL");
|
||||
return;
|
||||
}
|
||||
|
||||
const seq = ++seqRef.current;
|
||||
let targetUrl = url.trim();
|
||||
|
||||
// 如果没有协议前缀,默认使用 https://
|
||||
// If no protocol prefix, default to https://
|
||||
if (!targetUrl.startsWith("http://") && !targetUrl.startsWith("https://")) {
|
||||
targetUrl = `https://${targetUrl}`;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ const Tool: FC = () => {
|
||||
const time = endTime - startTime;
|
||||
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : "请求失败";
|
||||
error instanceof Error ? error.message : "Request failed";
|
||||
|
||||
const newResult: PingResult = {
|
||||
seq,
|
||||
@@ -117,7 +117,7 @@ const Tool: FC = () => {
|
||||
|
||||
const startPing = () => {
|
||||
if (!url.trim()) {
|
||||
toast.error("请输入 URL");
|
||||
toast.error("Please enter a URL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ const Tool: FC = () => {
|
||||
});
|
||||
seqRef.current = 0;
|
||||
|
||||
// 立即执行第一次 ping
|
||||
// Execute first ping immediately
|
||||
ping();
|
||||
|
||||
// 然后每秒执行一次
|
||||
// Then execute every second
|
||||
intervalRef.current = window.setInterval(ping, 1000);
|
||||
};
|
||||
|
||||
@@ -149,7 +149,7 @@ const Tool: FC = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// 自动滚动到底部
|
||||
// Auto-scroll to bottom
|
||||
if (resultsContainerRef.current) {
|
||||
resultsContainerRef.current.scrollTop =
|
||||
resultsContainerRef.current.scrollHeight;
|
||||
@@ -157,7 +157,7 @@ const Tool: FC = () => {
|
||||
}, [results]);
|
||||
|
||||
useEffect(() => {
|
||||
// 清理定时器
|
||||
// Cleanup timer
|
||||
return () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
@@ -172,9 +172,9 @@ const Tool: FC = () => {
|
||||
<div className="flex flex-col gap-4 h-full">
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<label className="text-sm font-medium">目标 URL 或 IP</label>
|
||||
<label className="text-sm font-medium">Target URL or IP</label>
|
||||
<Input
|
||||
placeholder="例如: example.com 或 https://example.com"
|
||||
placeholder="e.g. example.com or https://example.com"
|
||||
value={url}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
disabled={running}
|
||||
@@ -184,11 +184,11 @@ const Tool: FC = () => {
|
||||
<div className="flex gap-2">
|
||||
{!running ? (
|
||||
<Button onClick={startPing} className="flex-1">
|
||||
开始 Ping
|
||||
Start Ping
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={stopPing} variant="destructive" className="flex-1">
|
||||
停止
|
||||
Stop
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
@@ -196,23 +196,23 @@ const Tool: FC = () => {
|
||||
|
||||
{stats.sent > 0 && (
|
||||
<div className="border rounded-md p-3 bg-card text-card-foreground">
|
||||
<div className="text-sm font-medium mb-2">统计信息</div>
|
||||
<div className="text-sm font-medium mb-2">Statistics</div>
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div className="text-muted-foreground">已发送:</div>
|
||||
<div>{stats.sent} 包</div>
|
||||
<div className="text-muted-foreground">已接收:</div>
|
||||
<div>{stats.received} 包</div>
|
||||
<div className="text-muted-foreground">丢失:</div>
|
||||
<div className="text-muted-foreground">Sent:</div>
|
||||
<div>{stats.sent} packets</div>
|
||||
<div className="text-muted-foreground">Received:</div>
|
||||
<div>{stats.received} packets</div>
|
||||
<div className="text-muted-foreground">Lost:</div>
|
||||
<div>
|
||||
{stats.lost} 包 ({lossRate}%)
|
||||
{stats.lost} packets ({lossRate}%)
|
||||
</div>
|
||||
{stats.received > 0 && (
|
||||
<>
|
||||
<div className="text-muted-foreground">最小延迟:</div>
|
||||
<div className="text-muted-foreground">Min Latency:</div>
|
||||
<div>{stats.min.toFixed(2)} ms</div>
|
||||
<div className="text-muted-foreground">最大延迟:</div>
|
||||
<div className="text-muted-foreground">Max Latency:</div>
|
||||
<div>{stats.max.toFixed(2)} ms</div>
|
||||
<div className="text-muted-foreground">平均延迟:</div>
|
||||
<div className="text-muted-foreground">Avg Latency:</div>
|
||||
<div>{stats.avg.toFixed(2)} ms</div>
|
||||
</>
|
||||
)}
|
||||
@@ -222,7 +222,7 @@ const Tool: FC = () => {
|
||||
|
||||
{results.length > 0 && (
|
||||
<div className="flex flex-col gap-2 flex-1 overflow-hidden">
|
||||
<div className="text-sm font-medium">Ping 结果:</div>
|
||||
<div className="text-sm font-medium">Ping Results:</div>
|
||||
<div
|
||||
ref={resultsContainerRef}
|
||||
className="flex-1 overflow-auto space-y-1 font-mono text-sm border rounded-md p-3 bg-card"
|
||||
@@ -238,7 +238,7 @@ const Tool: FC = () => {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
seq={result.seq} 请求超时
|
||||
seq={result.seq} Request timeout
|
||||
{result.error && ` (${result.error})`}
|
||||
</>
|
||||
)}
|
||||
@@ -247,7 +247,7 @@ const Tool: FC = () => {
|
||||
{running && (
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<Loader2 className="size-3 animate-spin" />
|
||||
运行中...
|
||||
Running...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user