diff --git a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx index c01f1b9..756c5ca 100644 --- a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx @@ -1,16 +1,13 @@ "use client"; -import { useTranslations } from 'next-intl'; import { ServerApi } from "../../types/nezha-api"; import ServerCard from "../../../../components/ServerCard"; import { nezhaFetcher } from "../../../../lib/utils"; import useSWR from "swr"; import getEnv from "../../../../lib/env-entry"; export default function ServerListClient() { - const { - data - } = useSWR("/api/server", nezhaFetcher, { - refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 2000 + const { data } = useSWR("/api/server", nezhaFetcher, { + refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 2000, }); if (!data) return null; const sortedServers = data.result.sort((a, b) => { @@ -21,7 +18,11 @@ export default function ServerListClient() { if (b.display_index) return 1; return a.id - b.id; }); - return
- {sortedServers.map(serverInfo => )} -
; -} \ No newline at end of file + return ( +
+ {sortedServers.map((serverInfo) => ( + + ))} +
+ ); +} diff --git a/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx b/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx index 4b4fdeb..85a6af6 100644 --- a/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx @@ -1,6 +1,6 @@ "use client"; -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; import { Card, CardContent } from "../../../../components/ui/card"; import blogMan from "../../../../public/blog-man.webp"; import Image from "next/image"; @@ -11,24 +11,29 @@ import { ServerApi } from "../../types/nezha-api"; import getEnv from "../../../../lib/env-entry"; export default function ServerOverviewClient() { const t = useTranslations("ServerOverviewClient"); - const { - data - } = useSWR("/api/server", nezhaFetcher); + const { data } = useSWR("/api/server", nezhaFetcher); const disableCartoon = getEnv("NEXT_PUBLIC_DisableCartoon") === "true"; - return
+ return ( +
-

{t('p_816-881_Totalservers')}

+

+ {t("p_816-881_Totalservers")} +

- {data ?
+ {data ? ( +
{data?.result.length} -
:
+
+ ) : ( +
-
} +
+ )}
@@ -36,17 +41,23 @@ export default function ServerOverviewClient() {
-

{t('p_1610-1676_Onlineservers')}

+

+ {t("p_1610-1676_Onlineservers")} +

- {data ?
+ {data ? ( +
{data?.live_servers} -
:
+
+ ) : ( +
-
} +
+ )}
@@ -54,17 +65,23 @@ export default function ServerOverviewClient() {
-

{t('p_2532-2599_Offlineservers')}

+

+ {t("p_2532-2599_Offlineservers")} +

- {data ?
+ {data ? ( +
{data?.offline_servers} -
:
+
+ ) : ( +
-
} +
+ )}
@@ -72,15 +89,30 @@ export default function ServerOverviewClient() {
-

{t('p_3463-3530_Totalbandwidth')}

- {data ?

+

+ {t("p_3463-3530_Totalbandwidth")} +

+ {data ? ( +

{formatBytes(data?.total_bandwidth)} -

:
+

+ ) : ( +
-
} +
+ )}
- {!disableCartoon && {"Hamster1963"}} + {!disableCartoon && ( + {"Hamster1963"} + )}
-
; -} \ No newline at end of file +
+ ); +} diff --git a/app/[locale]/(main)/footer.tsx b/app/[locale]/(main)/footer.tsx index 920c271..4bfcffc 100644 --- a/app/[locale]/(main)/footer.tsx +++ b/app/[locale]/(main)/footer.tsx @@ -1,14 +1,25 @@ -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; export default function Footer() { const t = useTranslations("Footer"); - return + ); +} diff --git a/app/[locale]/(main)/header.tsx b/app/[locale]/(main)/header.tsx index fcb3ac8..88ad997 100644 --- a/app/[locale]/(main)/header.tsx +++ b/app/[locale]/(main)/header.tsx @@ -1,6 +1,6 @@ "use client"; -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; import React, { useEffect, useRef, useState } from "react"; import Image from "next/image"; import { Separator } from "../../../components/ui/separator"; @@ -8,20 +8,34 @@ import { DateTime } from "luxon"; import { ModeToggle } from "../../../components/ThemeSwitcher"; function Header() { const t = useTranslations("Header"); - return
+ return ( +
- apple-touch-icon + apple-touch-icon
NezhaDash - -

{t('p_1079-1199_Simpleandbeautifuldashbo')}

+ +

+ {t("p_1079-1199_Simpleandbeautifuldashbo")} +

-
; +
+ ); } // https://github.com/streamich/react-use/blob/master/src/useInterval.ts @@ -46,16 +60,24 @@ function Overview() { }, []); const timeOption = DateTime.TIME_SIMPLE; timeOption.hour12 = true; - const [timeString, setTimeString] = useState(DateTime.now().setLocale("en-US").toLocaleString(timeOption)); + const [timeString, setTimeString] = useState( + DateTime.now().setLocale("en-US").toLocaleString(timeOption), + ); useInterval(() => { setTimeString(DateTime.now().setLocale("en-US").toLocaleString(timeOption)); }, 1000); - return
-

{t('p_2277-2331_Overview')}

+ return ( +
+

{t("p_2277-2331_Overview")}

-

{t('p_2390-2457_wherethetimeis')}

- {mouted &&

{timeString}

} +

+ {t("p_2390-2457_wherethetimeis")} +

+ {mouted && ( +

{timeString}

+ )}
-
; +
+ ); } -export default Header; \ No newline at end of file +export default Header; diff --git a/app/[locale]/(main)/layout.tsx b/app/[locale]/(main)/layout.tsx index bbaa151..ed20e30 100644 --- a/app/[locale]/(main)/layout.tsx +++ b/app/[locale]/(main)/layout.tsx @@ -1,18 +1,18 @@ -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; import React from "react"; import Header from "@/app/[locale]/(main)/header"; import Footer from "./footer"; type DashboardProps = { children: React.ReactNode; }; -export default function MainLayout({ - children -}: DashboardProps) { - return
-
-
- {children} -
-
-
; -} \ No newline at end of file +export default function MainLayout({ children }: DashboardProps) { + return ( +
+
+
+ {children} +
+
+
+ ); +} diff --git a/app/[locale]/(main)/page.tsx b/app/[locale]/(main)/page.tsx index b3a0b2c..32e9f4b 100644 --- a/app/[locale]/(main)/page.tsx +++ b/app/[locale]/(main)/page.tsx @@ -1,20 +1,26 @@ -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; import ServerList from "../../../components/ServerList"; import ServerOverview from "../../../components/ServerOverview"; import getEnv from "../../../lib/env-entry"; import { GetNezhaData } from "../../../lib/serverFetch"; import { SWRConfig } from "swr"; const disablePrefetch = getEnv("ServerDisablePrefetch") === "true"; -const fallback = disablePrefetch ? {} : { - "/api/server": GetNezhaData() -}; +const fallback = disablePrefetch + ? {} + : { + "/api/server": GetNezhaData(), + }; export default function Home() { - return + return ( +
-
; -} \ No newline at end of file +
+ ); +} diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index f6b3307..fd67dbc 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -1,22 +1,23 @@ // @auto-i18n-check. Please do not delete the line. import React from "react"; -import {NextIntlClientProvider, useMessages} from 'next-intl'; +import { NextIntlClientProvider, useMessages } from "next-intl"; export default function LocaleLayout({ - children, - params: {locale} - }: { - children: React.ReactNode; params: { locale: string }; + children, + params: { locale }, +}: { + children: React.ReactNode; + params: { locale: string }; }) { - const messages = useMessages(); - return ( - - + const messages = useMessages(); + return ( + + - {children} + {children} - - - ); + + + ); } diff --git a/app/[locale]/not-found.tsx b/app/[locale]/not-found.tsx index 6f4d31a..ad0c9a7 100644 --- a/app/[locale]/not-found.tsx +++ b/app/[locale]/not-found.tsx @@ -1,16 +1,30 @@ -import { useTranslations } from 'next-intl'; +import { useTranslations } from "next-intl"; import Image from "next/image"; import Link from "next/link"; export default function NotFoundPage() { const t = useTranslations("NotFoundPage"); - return
+ return ( +
- TARDIS + TARDIS
-

{t('h1_490-590_404NotFound')}

-

{t('p_601-665_TARDISERROR')}

- {t('Link_676-775_Doctor')} +

+ {t("h1_490-590_404NotFound")} +

+

+ {t("p_601-665_TARDISERROR")} +

+ + {t("Link_676-775_Doctor")} +
-
; -} \ No newline at end of file +
+ ); +} diff --git a/auto-i18n-config.json b/auto-i18n-config.json index c7648db..bbf5176 100644 --- a/auto-i18n-config.json +++ b/auto-i18n-config.json @@ -1,15 +1,10 @@ { - "defaultLang": "en", - "translatorServerName": "azure", - "needLangs": [ - "en", - "zh", - "zh-t", - "ja" - ], - "brandWords": [], - "unMoveToLocaleDirFiles": [], - "enableStaticRendering": false, - "enableSubPageRedirectToLocale": false, - "disableDefaultLangRedirect": true -} \ No newline at end of file + "defaultLang": "en", + "translatorServerName": "azure", + "needLangs": ["en", "zh", "zh-t", "ja"], + "brandWords": [], + "unMoveToLocaleDirFiles": [], + "enableStaticRendering": false, + "enableSubPageRedirectToLocale": false, + "disableDefaultLangRedirect": true +} diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index a881292..666e158 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -1,3 +1,4 @@ +import { useTranslations } from "next-intl"; import { NezhaAPISafe } from "../app/[locale]/types/nezha-api"; import ServerUsageBar from "@/components/ServerUsageBar"; import { Card } from "@/components/ui/card"; @@ -16,6 +17,7 @@ export default function ServerCard({ }: { serverInfo: NezhaAPISafe; }) { + const t = useTranslations("ServerCard"); const { name, country_code, online, cpu, up, down, mem, stg, ...props } = formatNezhaInfo(serverInfo); @@ -55,36 +57,46 @@ export default function ServerCard({
-
-

CPU

+
+ {" "} + {/* 设置固定宽度 */} +

{t("CPU")}

{cpu.toFixed(2)}%
-
-

Mem

+
+ {" "} + {/* 设置固定宽度 */} +

{t("Mem")}

{mem.toFixed(2)}%
-
-

STG

+
+ {" "} + {/* 设置固定宽度 */} +

{t("STG")}

{stg.toFixed(2)}%
-
-

Upload

+
+ {" "} + {/* 设置固定宽度 */} +

{t("Upload")}

{up.toFixed(2)} Mb/s
-
-

Download

+
+ {" "} + {/* 设置固定宽度 */} +

{t("Download")}

{down.toFixed(2)} Mb/s @@ -122,7 +134,7 @@ export default function ServerCard({
-

Offline

+

{t("Offline")}

diff --git a/components/ServerCardPopover.tsx b/components/ServerCardPopover.tsx index 2b03835..b886ec5 100644 --- a/components/ServerCardPopover.tsx +++ b/components/ServerCardPopover.tsx @@ -1,3 +1,4 @@ +import { useTranslations } from "next-intl"; import { NezhaAPISafe } from "../app/[locale]/types/nezha-api"; import { cn, formatBytes } from "@/lib/utils"; @@ -31,39 +32,40 @@ export default function ServerCardPopover({ host: NezhaAPISafe["host"]; status: NezhaAPISafe["status"]; }) { + const t = useTranslations("ServerCardPopover"); return (
item).join(", ")}`} />
diff --git a/components/ThemeSwitcher.tsx b/components/ThemeSwitcher.tsx index 5830ade..d98794e 100644 --- a/components/ThemeSwitcher.tsx +++ b/components/ThemeSwitcher.tsx @@ -1,5 +1,6 @@ "use client"; +import { useTranslations } from "next-intl"; import { Moon, Sun } from "lucide-react"; import { useTheme } from "next-themes"; import * as React from "react"; @@ -14,7 +15,7 @@ import { export function ModeToggle() { const { setTheme } = useTheme(); - + const t = useTranslations("ThemeSwitcher"); return ( @@ -26,13 +27,13 @@ export function ModeToggle() { setTheme("light")}> - Light + {t("Light")} setTheme("dark")}> - Dark + {t("Dark")} setTheme("system")}> - System + {t("System")} diff --git a/i18n-metadata.ts b/i18n-metadata.ts index e7e755b..acf3a7c 100644 --- a/i18n-metadata.ts +++ b/i18n-metadata.ts @@ -1,24 +1,24 @@ // @auto-i18n-check. Please do not delete the line. export const localeItems = [ -{code: 'en', name: 'English'}, -{code: 'ja', name: '日本語'}, -{code: 'zh-t', name: '中文繁體'}, -{code: 'zh', name: '中文简体'}, -//{code: 'ar', name: 'العربية'}, -//{code: 'de', name: 'Deutsch'}, -//{code: 'es', name: 'Español'}, -//{code: 'fr', name: 'Français'}, -//{code: 'hi', name: 'हिन्दी'}, -//{code: 'id', name: 'Bahasa Indonesia'}, -//{code: 'it', name: 'Italiano'}, -//{code: 'ko', name: '한국어'}, -//{code: 'ms', name: 'Bahasa Melayu'}, -//{code: 'pt', name: 'Português'}, -//{code: 'ru', name: 'Русский'}, -//{code: 'th', name: 'ไทย'}, -//{code: 'vi', name: 'Tiếng Việt'}, + { code: "en", name: "English" }, + { code: "ja", name: "日本語" }, + { code: "zh-t", name: "中文繁體" }, + { code: "zh", name: "中文简体" }, + //{code: 'ar', name: 'العربية'}, + //{code: 'de', name: 'Deutsch'}, + //{code: 'es', name: 'Español'}, + //{code: 'fr', name: 'Français'}, + //{code: 'hi', name: 'हिन्दी'}, + //{code: 'id', name: 'Bahasa Indonesia'}, + //{code: 'it', name: 'Italiano'}, + //{code: 'ko', name: '한국어'}, + //{code: 'ms', name: 'Bahasa Melayu'}, + //{code: 'pt', name: 'Português'}, + //{code: 'ru', name: 'Русский'}, + //{code: 'th', name: 'ไทย'}, + //{code: 'vi', name: 'Tiếng Việt'}, ]; export const locales = localeItems.map((item) => item.code); -export const defaultLocale = 'en'; +export const defaultLocale = "en"; diff --git a/i18n.ts b/i18n.ts index 941b5a6..2c40c0d 100644 --- a/i18n.ts +++ b/i18n.ts @@ -1,14 +1,14 @@ // @auto-i18n-check. Please do not delete the line. -import {notFound} from 'next/navigation'; -import {getRequestConfig} from 'next-intl/server'; -import {locales} from "./i18n-metadata"; +import { notFound } from "next/navigation"; +import { getRequestConfig } from "next-intl/server"; +import { locales } from "./i18n-metadata"; -export default getRequestConfig(async ({locale}) => { - // Validate that the incoming `locale` parameter is valid - if (!locales.includes(locale as any)) notFound(); +export default getRequestConfig(async ({ locale }) => { + // Validate that the incoming `locale` parameter is valid + if (!locales.includes(locale as any)) notFound(); - return { - messages: (await import(`./messages/${locale}.json`)).default - }; + return { + messages: (await import(`./messages/${locale}.json`)).default, + }; }); diff --git a/messages/en.json b/messages/en.json index c9497a2..0b7e0f4 100644 --- a/messages/en.json +++ b/messages/en.json @@ -5,6 +5,30 @@ "p_2532-2599_Offlineservers": "Offline servers", "p_3463-3530_Totalbandwidth": "Total bandwidth" }, + "ServerCard": { + "CPU": "CPU", + "Mem": "Mem", + "STG": "STG", + "Upload": "Upload", + "Download": "Download", + "Offline": "Offline" + }, + "ServerCardPopover": { + "System": "System", + "CPU": "CPU", + "Mem": "Mem", + "STG": "STG", + "Swap": "Swap", + "Network": "Network", + "Load": "Load", + "Online": "Online", + "Offline": "Offline" + }, + "ThemeSwitcher": { + "Light": "Light", + "Dark": "Dark", + "System": "System" + }, "Footer": { "p_146-598_Findthecodeon": "Find the code on", "a_303-585_GitHub": "GitHub", @@ -23,4 +47,4 @@ "p_601-665_TARDISERROR": "TARDIS ERROR!", "Link_676-775_Doctor": "Doctor?" } -} \ No newline at end of file +} diff --git a/messages/ja.json b/messages/ja.json index 7b36885..ec840dd 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -5,6 +5,30 @@ "p_2532-2599_Offlineservers": "オフラインサーバー", "p_3463-3530_Totalbandwidth": "総流量" }, + "ServerCard": { + "CPU": "CPU", + "Mem": "Mem", + "STG": "STG", + "Upload": "Upload", + "Download": "Download", + "Offline": "Offline" + }, + "ServerCardPopover": { + "System": "システム", + "CPU": "CPU", + "Mem": "メモリ", + "STG": "ストレージ", + "Swap": "スワップ", + "Network": "ネットワーク", + "Load": "負荷", + "Online": "オンライン時間", + "Offline": "オフライン" + }, + "ThemeSwitcher": { + "Light": "ライト", + "Dark": "ダーク", + "System": "システム" + }, "Footer": { "p_146-598_Findthecodeon": "コードのオープンソース", "a_303-585_GitHub": "GitHub", @@ -23,4 +47,4 @@ "p_601-665_TARDISERROR": "ターディスエラー!", "Link_676-775_Doctor": "Doctor?" } -} \ No newline at end of file +} diff --git a/messages/zh-t.json b/messages/zh-t.json index 2652cf0..a8027b6 100644 --- a/messages/zh-t.json +++ b/messages/zh-t.json @@ -5,6 +5,30 @@ "p_2532-2599_Offlineservers": "離線伺服器", "p_3463-3530_Totalbandwidth": "總流量" }, + "ServerCard": { + "CPU": "CPU", + "Mem": "記憶體", + "STG": "儲存", + "Upload": "上傳", + "Download": "下載", + "Offline": "離線" + }, + "ServerCardPopover": { + "System": "系統", + "CPU": "CPU", + "Mem": "記憶體", + "STG": "儲存", + "Swap": "虛擬記憶體", + "Network": "網路", + "Load": "負載", + "Online": "在線時間", + "Offline": "離線" + }, + "ThemeSwitcher": { + "Light": "亮色", + "Dark": "暗色", + "System": "系統" + }, "Footer": { "p_146-598_Findthecodeon": "程式碼開源", "a_303-585_GitHub": "GitHub", @@ -23,4 +47,4 @@ "p_601-665_TARDISERROR": "TARDIS 錯誤!", "Link_676-775_Doctor": "Doctor?" } -} \ No newline at end of file +} diff --git a/messages/zh.json b/messages/zh.json index 55c8a19..166ac55 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -5,6 +5,30 @@ "p_2532-2599_Offlineservers": "离线服务器", "p_3463-3530_Totalbandwidth": "总流量" }, + "ServerCard": { + "CPU": "CPU", + "Mem": "内存", + "STG": "存储", + "Upload": "上传", + "Download": "下载", + "Offline": "离线" + }, + "ServerCardPopover": { + "System": "系统", + "CPU": "CPU", + "Mem": "内存", + "STG": "存储", + "Swap": "虚拟内存", + "Network": "网络", + "Load": "负载", + "Online": "在线时间", + "Offline": "离线" + }, + "ThemeSwitcher": { + "Light": "亮色", + "Dark": "暗色", + "System": "系统" + }, "Footer": { "p_146-598_Findthecodeon": "代码开源在", "a_303-585_GitHub": "GitHub", @@ -23,4 +47,4 @@ "p_601-665_TARDISERROR": "TARDIS 错误!", "Link_676-775_Doctor": "Doctor?" } -} \ No newline at end of file +} diff --git a/middleware.ts b/middleware.ts index f165337..a4b787c 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,21 +1,21 @@ // @auto-i18n-check. Please do not delete the line. -import createMiddleware from 'next-intl/middleware'; -import {locales} from "./i18n-metadata"; +import createMiddleware from "next-intl/middleware"; +import { locales } from "./i18n-metadata"; export default createMiddleware({ - // A list of all locales that are supported - locales: locales, + // A list of all locales that are supported + locales: locales, - // Used when no locale matches - defaultLocale: 'en', + // Used when no locale matches + defaultLocale: "en", - // 'always': This is the default, The home page will also be redirected to the default language, such as www.abc.com to www.abc.com/en - // 'as-needed': The default page is not redirected. For example, if you open www.abc.com, it is still www.abc.com - localePrefix: 'as-needed', + // 'always': This is the default, The home page will also be redirected to the default language, such as www.abc.com to www.abc.com/en + // 'as-needed': The default page is not redirected. For example, if you open www.abc.com, it is still www.abc.com + localePrefix: "as-needed", }); export const config = { - // Match only internationalized pathnames - matcher: ['/', '/(en|zh|zh-t|ja)/:path*'] + // Match only internationalized pathnames + matcher: ["/", "/(en|zh|zh-t|ja)/:path*"], }; diff --git a/next.config.mjs b/next.config.mjs index 17c3658..03f58d8 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,4 @@ -import createNextIntlPlugin from 'next-intl/plugin'; +import createNextIntlPlugin from "next-intl/plugin"; const withNextIntl = createNextIntlPlugin(); import withPWAInit from "@ducanh2912/next-pwa"; const withPWA = withPWAInit({ @@ -8,13 +8,13 @@ const withPWA = withPWAInit({ reloadOnOnline: true, disable: false, workboxOptions: { - disableDevLogs: true - } + disableDevLogs: true, + }, }); /** @type {import('next').NextConfig} */ const nextConfig = { // output: "standalone", - reactStrictMode: true + reactStrictMode: true, }; -export default withPWA(withNextIntl(nextConfig)); \ No newline at end of file +export default withPWA(withNextIntl(nextConfig));