feat: ip info i18n

This commit is contained in:
hamster1963 2024-12-12 11:00:38 +08:00
parent 33d22fa8b3
commit e0e9faaa24
5 changed files with 64 additions and 23 deletions

View File

@ -4,9 +4,12 @@ import { IPInfo } from "@/app/api/server-ip/route";
import { Loader } from "@/components/loading/Loader"; import { Loader } from "@/components/loading/Loader";
import { Card, CardContent } from "@/components/ui/card"; import { Card, CardContent } from "@/components/ui/card";
import { nezhaFetcher } from "@/lib/utils"; import { nezhaFetcher } from "@/lib/utils";
import { useTranslations } from "next-intl";
import useSWRImmutable from "swr/immutable"; import useSWRImmutable from "swr/immutable";
export default function ServerIPInfo({ server_id }: { server_id: number }) { export default function ServerIPInfo({ server_id }: { server_id: number }) {
const t = useTranslations("IPInfo");
const { data } = useSWRImmutable<IPInfo>( const { data } = useSWRImmutable<IPInfo>(
`/api/server-ip?server_id=${server_id}`, `/api/server-ip?server_id=${server_id}`,
nezhaFetcher, nezhaFetcher,
@ -36,7 +39,7 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Origin ASN"}</p> <p className="text-xs text-muted-foreground">{t("asn_number")}</p>
<div className="text-xs"> <div className="text-xs">
AS{data.asn.autonomous_system_number} AS{data.asn.autonomous_system_number}
</div> </div>
@ -47,7 +50,7 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
{"Registered Country"} {t("registered_country")}
</p> </p>
<div className="text-xs"> <div className="text-xs">
{data.city.registered_country?.names.en} {data.city.registered_country?.names.en}
@ -55,24 +58,6 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Time Zone"}</p>
<div className="text-xs">{data.city.location?.time_zone}</div>
</section>
</CardContent>
</Card>
{data.city.postal && (
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Postal"}</p>
<div className="text-xs">{data.city.postal?.code}</div>
</section>
</CardContent>
</Card>
)}
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
@ -84,7 +69,7 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"City"}</p> <p className="text-xs text-muted-foreground">{t("city")}</p>
<div className="text-xs">{data.city.city?.names.en}</div> <div className="text-xs">{data.city.city?.names.en}</div>
</section> </section>
</CardContent> </CardContent>
@ -92,7 +77,7 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Longitude"}</p> <p className="text-xs text-muted-foreground">{t("longitude")}</p>
<div className="text-xs">{data.city.location?.longitude}</div> <div className="text-xs">{data.city.location?.longitude}</div>
</section> </section>
</CardContent> </CardContent>
@ -100,11 +85,31 @@ export default function ServerIPInfo({ server_id }: { server_id: number }) {
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Latitude"}</p> <p className="text-xs text-muted-foreground">{t("latitude")}</p>
<div className="text-xs">{data.city.location?.latitude}</div> <div className="text-xs">{data.city.location?.latitude}</div>
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{t("time_zone")}</p>
<div className="text-xs">{data.city.location?.time_zone}</div>
</section>
</CardContent>
</Card>
{data.city.postal && (
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">
{t("postal_code")}
</p>
<div className="text-xs">{data.city.postal?.code}</div>
</section>
</CardContent>
</Card>
)}
</section> </section>
</> </>
); );

View File

@ -55,6 +55,15 @@
"avg_delay": "Latency", "avg_delay": "Latency",
"chart_fetch_error_message": "Failed to fetch network data, please check if the server monitoring is enabled" "chart_fetch_error_message": "Failed to fetch network data, please check if the server monitoring is enabled"
}, },
"IPInfo": {
"asn_number": "Origin ASN",
"registered_country": "Registered Country",
"time_zone": "Time Zone",
"postal_code": "Postal Code",
"city": "City",
"longitude": "Longitude",
"latitude": "Latitude"
},
"NetworkChart": { "NetworkChart": {
"ServerMonitorCount": "Services" "ServerMonitorCount": "Services"
}, },

View File

@ -55,6 +55,15 @@
"avg_delay": "遅延", "avg_delay": "遅延",
"chart_fetch_error_message": "ネットワークデータの取得に失敗しました。サーバーの監視が有効になっているかどうかを確認してください" "chart_fetch_error_message": "ネットワークデータの取得に失敗しました。サーバーの監視が有効になっているかどうかを確認してください"
}, },
"IPInfo": {
"asn_number": "ASN",
"registered_country": "Registered Country",
"time_zone": "時刻",
"postal_code": "郵便番号",
"city": "都市",
"longitude": "経度",
"latitude": "緯度"
},
"NetworkChart": { "NetworkChart": {
"ServerMonitorCount": "サービス" "ServerMonitorCount": "サービス"
}, },

View File

@ -55,6 +55,15 @@
"avg_delay": "延遲", "avg_delay": "延遲",
"chart_fetch_error_message": "獲取網絡數據失敗,請檢查是否開啟服務端監控" "chart_fetch_error_message": "獲取網絡數據失敗,請檢查是否開啟服務端監控"
}, },
"IPInfo": {
"asn_number": "ASN Number",
"registered_country": "注册地區",
"time_zone": "時區",
"postal_code": "郵遞區號",
"city": "城市",
"longitude": "經度",
"latitude": "緯度"
},
"NetworkChart": { "NetworkChart": {
"ServerMonitorCount": "個監測服務" "ServerMonitorCount": "個監測服務"
}, },

View File

@ -58,6 +58,15 @@
"NetworkChart": { "NetworkChart": {
"ServerMonitorCount": "个监控服务" "ServerMonitorCount": "个监控服务"
}, },
"IPInfo": {
"asn_number": "ASN 编号",
"registered_country": "注册地",
"time_zone": "时区",
"postal_code": "邮政编码",
"city": "城市",
"longitude": "经度",
"latitude": "纬度"
},
"ServerDetailClient": { "ServerDetailClient": {
"detail_fetch_error_message": "获取服务器详情失败,请检查您的环境变量并检查服务器控制台", "detail_fetch_error_message": "获取服务器详情失败,请检查您的环境变量并检查服务器控制台",
"status": "状态", "status": "状态",