Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: Implement country name internationalization using `Intl.DisplayNames` and fix desktop scrollbar layout shift.

luoleie0074c9f7e77
diff --git a/CHANGELOG.en.md b/CHANGELOG.en.md
index 9bf2624..6f60bfc 100644
--- a/CHANGELOG.en.md
+++ b/CHANGELOG.en.md
@@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.3.5] - 2026-03-03
+
+### Added
+
+- **WebSocket Summary Data Enhancement** 📊
+ - WebSocket broadcasts now include total proxy count and rule count in summary data
+ - Refined dashboard data fetching strategy during active WebSocket connections
+- **Responsive Overview List Display** 📐
+ - New `useResponsiveItemCount` hook dynamically adjusts list item count based on viewport height
+ - Top Domains card now includes traffic progress bars for visual proportion display
+- **Country/Region Name Internationalization** 🌍
+ - Replaced manually-maintained country name mappings with `Intl.DisplayNames` API, supporting localized names for all 249 ISO country codes
+ - All region-related panels (overview, top list, traffic list, pie chart, world map, IP details) now display correctly localized country names
+ - Custom name overrides for specific regions ensure consistent display across different browser/OS CLDR versions
+- **New Logo** 🎨
+
+### Fixed
+
+- **Rules statistics not showing** 🐛
+ - Fixed Dashboard displaying 0 for total rules and total proxies after the 1.3.4 WebSocket summary optimization
+ - Root cause: `totalProxies`/`totalRules` were previously derived from `proxyStats`/`ruleStats` array lengths, but the summary optimization skipped fetching these arrays
+ - Fix: moved both counts into the WebSocket summary cache so they are always available
+- **Dashboard stuck in loading state during WebSocket connection**
+ - Fixed Dashboard showing infinite transition animation when WebSocket was in `connecting` state
+ - Refined `isTransitioning` logic to only show loading state when HTTP fallback data fetching is actually needed
+- **Settings toggle switch jitter** ⚡
+ - Fixed the Collect toggle and Active backend switch causing the entire backend list to flash with skeleton loading
+ - Changed to silent data refresh, avoiding unnecessary full re-renders
+- **Desktop dropdown menu scrollbar flicker**
+ - Fixed layout shift caused by scrollbar appearing/disappearing when opening dropdown menus, dialogs, or theme switcher
+ - Scrollbar space reservation now only applies on desktop (`pointer: fine`), preserving correct Radix popover positioning on mobile
+
## [1.3.4] - 2026-02-26
### Added
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 282dcb5..6bad498 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,38 @@
格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/),
并且本项目遵循 [语义化版本](https://semver.org/lang/zh-CN/spec/v2.0.0.html)。
+## [1.3.5] - 2026-03-03
+
+### 新增
+
+- **WebSocket 摘要数据增强** 📊
+ - WebSocket 推送新增代理节点总数和规则总数摘要字段
+ - 优化 Dashboard 在 WebSocket 连接期间的数据获取策略
+- **概览列表自适应展示** 📐
+ - 新增 `useResponsiveItemCount` Hook,根据窗口高度自动计算列表显示条目数
+ - Top Domains 卡片新增流量进度条,直观展示各域名流量占比
+- **国家/地区名称国际化** 🌍
+ - 使用 `Intl.DisplayNames` API 替代手动维护的国家名称映射,支持全部 249 个 ISO 国家代码的本地化翻译
+ - 中文界面下所有地区板块(概览、排行、列表、饼图、世界地图、IP 详情)均正确显示中文国家名
+ - 支持自定义名称覆盖,确保跨浏览器/系统版本显示一致
+- **新 Logo** 🎨
+
+### 修复
+
+- **规则统计不显示** 🐛
+ - 修复 1.3.4 WebSocket 摘要优化后,规则总数和代理总数在 Dashboard 上显示为 0 的问题
+ - 原因:`totalProxies`/`totalRules` 原先从 `proxyStats`/`ruleStats` 数组长度计算,但摘要优化跳过了这些数组的获取
+ - 修复方式:将这两个计数纳入 WebSocket 摘要缓存,确保始终可用
+- **Dashboard 在 WebSocket 连接中卡在加载状态**
+ - 修复 WebSocket 处于 `connecting` 状态时 Dashboard 无限显示过渡动画的问题
+ - 优化 `isTransitioning` 判断逻辑,仅在确实需要 HTTP 回退获取数据时显示加载状态
+- **Settings 开关切换抖动** ⚡
+ - 修复切换 Collect 开关和 Active 节点时整个后端列表闪烁骨架屏的问题
+ - 改为静默刷新数据,避免不必要的全量重渲染
+- **桌面端下拉菜单滚动条闪烁**
+ - 修复打开下拉菜单、弹窗、主题切换时页面滚动条出现/消失导致的布局跳动
+ - 仅在桌面端(`pointer: fine`)应用滚动条空间预留,不影响移动端 Radix 弹出层定位
+
## [1.3.4] - 2026-02-26
### 新增
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 5d94dd8..2f94619 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -143,10 +143,6 @@
* {
@apply border-border outline-ring/50;
}
- html {
- /* Prevent layout shift when scrollbar appears/disappears */
- scrollbar-gutter: stable;
- }
body {
@apply bg-background text-foreground antialiased;
font-family: var(--font-sans);
@@ -169,15 +165,24 @@
background-attachment: fixed;
}
- /* Prevent Radix UI scroll-lock from causing layout shift */
- /* scrollbar-gutter: stable already reserves space, so we override Radix's compensation */
- html[data-scroll-locked] {
- margin-right: 0 !important;
- }
-
- body[data-scroll-locked] {
- padding-right: 0 !important;
- margin-right: 0 !important;
+ /* Desktop only: prevent layout shift from classic (non-overlay) scrollbar */
+ /* Mobile/tablet uses overlay scrollbars that don't affect layout, so skip */
+ @media (pointer: fine) {
+ html {
+ overflow-y: scroll;
+ scrollbar-gutter: stable;
+ }
+
+ /* Override Radix scroll-lock compensation — scrollbar space is already reserved */
+ html[data-scroll-locked] {
+ overflow-y: scroll !important;
+ margin-right: 0 !important;
+ }
+
+ body[data-scroll-locked] {
+ padding-right: 0 !important;
+ margin-right: 0 !important;
+ }
}
}
diff --git a/apps/web/components/features/backend/backend-config-dialog.tsx b/apps/web/components/features/backend/backend-config-dialog.tsx
index ac20d01..e788905 100644
--- a/apps/web/components/features/backend/backend-config-dialog.tsx
+++ b/apps/web/components/features/backend/backend-config-dialog.tsx
@@ -774,8 +774,8 @@ export function BackendConfigDialog({
}
}, [open]);
- const loadBackends = async () => {
- setBackendsLoading(true);
+ const loadBackends = async (silent = false) => {
+ if (!silent) setBackendsLoading(true);
try {
const data = await api.getBackends();
// Parse URL for display/form rendering
@@ -798,7 +798,7 @@ export function BackendConfigDialog({
} catch (error) {
console.error("Failed to load backends:", error);
} finally {
- setBackendsLoading(false);
+ if (!silent) setBackendsLoading(false);
}
};
@@ -1131,7 +1131,7 @@ export function BackendConfigDialog({
try {
await api.setActiveBackend(id);
// Refresh local backend list to update UI (active state, eye icon)
- await loadBackends();
+ await loadBackends(true);
// Notify parent to refresh dashboard data
await onBackendChange?.();
// Show toast notification
@@ -1145,7 +1145,7 @@ export function BackendConfigDialog({
const handleToggleListening = async (id: number, listening: boolean) => {
try {
await api.setBackendListening(id, listening);
- await loadBackends();
+ await loadBackends(true);
await onBackendChange?.();
} catch (error: any) {
setErrorMessage(error.message || "Failed to update listening state");
diff --git a/apps/web/components/features/countries/country-top-list.tsx b/apps/web/components/features/countries/country-top-list.tsx
index 3071f72..012309f 100644
--- a/apps/web/components/features/countries/country-top-list.tsx
+++ b/apps/web/components/features/countries/country-top-list.tsx
@@ -7,6 +7,7 @@ import { CountryFlag } from "./country-flag";
import { OverviewCard } from "@/components/common";
import { TopListItem } from "@/components/common";
import { Button } from "@/components/ui/button";
+import { useCountryName } from "@/lib/i18n-country";
import type { CountryStats } from "@neko-master/shared";
interface CountryTopListProps {
@@ -28,6 +29,7 @@ function getContinentColor(continent: string): string {
export function CountryTopList({ data, limit = 7, onViewAll }: CountryTopListProps) {
const t = useTranslations("topCountries");
const countriesT = useTranslations("countries");
+ const countryName = useCountryName();
const { countries, totalTraffic } = useMemo(() => {
if (!data) return { countries: [], totalTraffic: 0 };
@@ -71,7 +73,7 @@ export function CountryTopList({ data, limit = 7, onViewAll }: CountryTopListPro
key={country.country}
rank={index + 1}
icon={<CountryFlag country={country.country} className="h-4 w-6" />}
- title={country.countryName || country.country}
+ title={countryName(country.country)}
subtitle={country.continent}
value={country.total}
total={totalTraffic}
diff --git a/apps/web/components/features/countries/country-traffic-chart.tsx b/apps/web/components/features/countries/country-traffic-chart.tsx
index 5542c3a..6d08c71 100644
--- a/apps/web/components/features/countries/country-traffic-chart.tsx
+++ b/apps/web/components/features/countries/country-traffic-chart.tsx
@@ -7,6 +7,7 @@ import { useTranslations } from "next-intl";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { CountryFlag } from "./country-flag";
import { formatBytes, formatNumber } from "@/lib/utils";
+import { useCountryName } from "@/lib/i18n-country";
import type { CountryStats } from "@neko-master/shared";
interface CountryTrafficChartProps {
@@ -33,11 +34,12 @@ function getContinentColor(continent: string): string {
export function CountryTrafficChart({ data }: CountryTrafficChartProps) {
const t = useTranslations("countries");
const mapT = useTranslations("map");
+ const countryName = useCountryName();
const chartData = useMemo(() => {
if (!data) return [];
return data.map((country) => ({
- name: country.countryName || country.country,
+ name: countryName(country.country),
code: country.country,
value: country.totalDownload + country.totalUpload,
download: country.totalDownload,
@@ -46,7 +48,7 @@ export function CountryTrafficChart({ data }: CountryTrafficChartProps) {
continent: country.continent,
color: getContinentColor(country.continent),
}));
- }, [data]);
+ }, [data, countryName]);
const totalTraffic = useMemo(() => {
return chartData.reduce((sum, item) => sum + item.value, 0);
diff --git a/apps/web/components/features/countries/country-traffic-list.tsx b/apps/web/components/features/countries/country-traffic-list.tsx
index 9a9b6f6..4e9ce70 100644
--- a/apps/web/components/features/countries/country-traffic-list.tsx
+++ b/apps/web/components/features/countries/country-traffic-list.tsx
@@ -4,6 +4,7 @@ import { useMemo } from "react";
import { Link2 } from "lucide-react";
import { CountryFlag } from "./country-flag";
import { formatBytes, formatNumber } from "@/lib/utils";
+import { useCountryName } from "@/lib/i18n-country";
import type { CountryStats } from "@neko-master/shared";
interface CountryTrafficListProps {
@@ -26,6 +27,7 @@ export function CountryTrafficList({
data,
sortBy = "traffic",
}: CountryTrafficListProps) {
+ const countryName = useCountryName();
const countries = useMemo(() => {
if (!data) return [];
return data
@@ -70,8 +72,8 @@ export function CountryTrafficList({
{/* Header: Flag + Name + Total */}
<div className="flex items-center gap-2 mb-2">
<CountryFlag country={country.country} className="h-4 w-6" />
- <p className="flex-1 font-medium text-sm truncate" title={country.countryName || country.country}>
- {country.countryName || country.country}
+ <p className="flex-1 font-medium text-sm truncate" title={countryName(country.country)}>
+ {countryName(country.country)}
</p>
<span className="text-base font-bold tabular-nums whitespace-nowrap shrink-0 sm:hidden">
{formatBytes(country.total)}
diff --git a/apps/web/components/features/countries/world-traffic-map.tsx b/apps/web/components/features/countries/world-traffic-map.tsx
index d72a27a..0bc8d13 100644
--- a/apps/web/components/features/countries/world-traffic-map.tsx
+++ b/apps/web/components/features/countries/world-traffic-map.tsx
@@ -12,6 +12,7 @@ import { Globe, Info } from "lucide-react";
import { useTranslations } from "next-intl";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { formatBytes, formatNumber } from "@/lib/utils";
+import { useCountryName } from "@/lib/i18n-country";
import type { CountryStats } from "@neko-master/shared";
interface WorldTrafficMapProps {
@@ -47,6 +48,7 @@ const COUNTRY_NAME_MAPPING: Record<string, string> = {
export function WorldTrafficMap({ data }: WorldTrafficMapProps) {
const t = useTranslations("map");
+ const countryName = useCountryName();
const [hoveredCountry, setHoveredCountry] = useState<string | null>(null);
const [tooltipData, setTooltipData] = useState<{
country: string;
@@ -123,7 +125,7 @@ export function WorldTrafficMap({ data }: WorldTrafficMapProps) {
if (countryData && countryData.country !== "LOCAL") {
const rect = event.target.getBoundingClientRect();
setTooltipData({
- country: countryData.countryName || countryData.country,
+ country: countryName(countryData.country),
traffic: countryData.totalDownload + countryData.totalUpload,
download: countryData.totalDownload,
upload: countryData.totalUpload,
@@ -296,7 +298,7 @@ export function WorldTrafficMap({ data }: WorldTrafficMapProps) {
style={{ backgroundColor: colorScale(traffic) }}
/>
<span className="text-muted-foreground">
- {country.countryName || country.country}
+ {countryName(country.country)}
</span>
<span className="font-medium">{formatBytes(traffic)}</span>
</div>
diff --git a/apps/web/components/features/stats/table/expanded-details.tsx b/apps/web/components/features/stats/table/expanded-details.tsx
index b10d94c..c843566 100644
--- a/apps/web/components/features/stats/table/expanded-details.tsx
+++ b/apps/web/components/features/stats/table/expanded-details.tsx
@@ -7,6 +7,7 @@ import { Favicon } from "@/components/common";
import { DomainPreview } from "@/components/features/domains";
import { getDomainColor, getIPGradient } from "@/lib/stats-utils";
import { formatBytes, formatNumber } from "@/lib/utils";
+import { useCountryName } from "@/lib/i18n-country";
import { normalizeGeoIP } from "@neko-master/shared";
import type { DomainStats, IPStats, ProxyTrafficStats } from "@neko-master/shared";
@@ -329,6 +330,8 @@ export function DomainExpandedDetails({
showProxyTraffic = true,
showFullProxyChains = false,
}: DomainExpandedDetailsProps) {
+ const localizedName = useCountryName();
+
if (!richExpand) {
return (
<div className="px-4 sm:px-5 pb-4 bg-secondary/5">
@@ -387,7 +390,7 @@ export function DomainExpandedDetails({
{ipDetails.map((ipStat) => {
const geo = normalizeGeoIP(ipStat.geoIP);
const country = geo?.countryCode;
- const location = geo?.countryName || geo?.countryCode || null;
+ const location = geo?.countryCode ? localizedName(geo.countryCode) : null;
const ipTraffic = ipStat.totalDownload + ipStat.totalUpload;
const percent = totalIPTraffic > 0 ? (ipTraffic / totalIPTraffic) * 100 : 0;
const downloadPercent = ipTraffic > 0 ? (ipStat.totalDownload / ipTraffic) * 100 : 0;
@@ -458,15 +461,15 @@ export function IPExpandedDetails({
const AssociatedDomainsTitleIcon = associatedDomainsIcon === "globe" ? Globe : Link2;
const domainsT = useTranslations("domains");
const ipsT = useTranslations("ips");
+ const localizedName = useCountryName();
const geo = normalizeGeoIP(ip.geoIP);
const countryCode = geo?.countryCode;
- const countryName = geo?.countryName;
const city = geo?.city || ipsT("unknown");
const asOrganization = geo?.asOrganization || ipsT("unknown");
const asnValue = ip.asn || ipsT("unknown");
- const hasLocation = Boolean(countryCode || countryName);
- const displayLocation = countryName || countryCode || ipsT("unknown");
+ const hasLocation = Boolean(countryCode);
+ const displayLocation = countryCode ? localizedName(countryCode) : ipsT("unknown");
const ipLookupDetails = showIPLookupDetails ? (
<div className="px-1">
@@ -478,7 +481,7 @@ export function IPExpandedDetails({
</p>
{hasLocation ? (
<span className="mt-1.5 flex min-w-0 items-center gap-1.5">
- <CountryFlag country={countryCode || countryName || "UN"} className="h-3.5 w-5" />
+ <CountryFlag country={countryCode || "UN"} className="h-3.5 w-5" />
<span className="truncate text-sm font-medium leading-5">{displayLocation}</span>
</span>
) : (
diff --git a/apps/web/components/features/stats/table/ip-preview.tsx b/apps/web/components/features/stats/table/ip-preview.tsx
index f55b179..b12fc96 100644
--- a/apps/web/components/features/stats/table/ip-preview.tsx
+++ b/apps/web/components/features/stats/table/ip-preview.tsx
@@ -7,6 +7,7 @@ import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { CountryFlag } from "@/components/features/countries/country-flag";
import { cn } from "@/lib/utils";
+import { useCountryName } from "@/lib/i18n-country";
import { normalizeGeoIP, type GeoIPInfo } from "@neko-master/shared";
interface IPPreviewProps {
@@ -48,12 +49,12 @@ export function IPPreview({
const geo = normalizeGeoIP(geoIP);
const countryCode = geo?.countryCode;
- const countryName = geo?.countryName;
+ const localizedName = useCountryName();
const city = geo?.city || unavailableLabel;
const asOrganization = geo?.asOrganization || unavailableLabel;
const asnValue = asn || unavailableLabel;
- const hasLocation = Boolean(countryCode || countryName);
- const displayLocation = countryName || countryCode || unavailableLabel;
+ const hasLocation = Boolean(countryCode);
+ const displayLocation = countryCode ? localizedName(countryCode) : unavailableLabel;
useEffect(() => {
return () => {
diff --git a/apps/web/components/features/stats/table/ip-stats-table.tsx b/apps/web/components/features/stats/table/ip-stats-table.tsx
index 2a2954c..29832df 100644
--- a/apps/web/components/features/stats/table/ip-stats-table.tsx
+++ b/apps/web/components/features/stats/table/ip-stats-table.tsx
@@ -49,6 +49,7 @@ import {
type IPSortKey,
type SortOrder,
} from "@/lib/stats-utils";
+import { useCountryName } from "@/lib/i18n-country";
import { normalizeGeoIP } from "@neko-master/shared";
import type { IPStats } from "@neko-master/shared";
@@ -109,6 +110,7 @@ export function IPStatsTable({
contextKey,
}: IPStatsTableProps) {
const t = useTranslations("ips");
+ const localizedName = useCountryName();
const detailTimeRange = useStableTimeRange(timeRange);
const isRemoteMode = mode === "remote";
@@ -433,7 +435,7 @@ export function IPStatsTable({
const isDesktopExpanded = expandedIP === ip.ip;
const isMobileActive = mobileDetailsOpen && mobileDetailIP?.ip === ip.ip;
const geo = normalizeGeoIP(ip.geoIP);
- const locationName = geo?.countryName || geo?.countryCode || null;
+ const locationName = geo?.countryCode ? localizedName(geo.countryCode) : null;
return (
<div key={ip.ip} className="group">
diff --git a/apps/web/components/overview/top-countries-simple.tsx b/apps/web/components/overview/top-countries-simple.tsx
index 190fcc1..edbec83 100644
--- a/apps/web/components/overview/top-countries-simple.tsx
+++ b/apps/web/components/overview/top-countries-simple.tsx
@@ -2,11 +2,12 @@
import React, { useMemo } from "react";
import { Globe, ArrowRight, BarChart3, Link2 } from "lucide-react";
-import { useTranslations, useLocale } from "next-intl";
+import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { CountryFlag } from "@/components/features/countries";
import { formatBytes, formatNumber, cn } from "@/lib/utils";
import { useResponsiveItemCount } from "@/lib/hooks/use-responsive-item-count";
+import { useCountryName } from "@/lib/i18n-country";
import type { CountryStats } from "@neko-master/shared";
interface TopCountriesSimpleProps {
@@ -17,33 +18,6 @@ interface TopCountriesSimpleProps {
isLoading?: boolean;
}
-const countryNamesEn: Record<string, string> = {
- "CN": "China", "US": "United States", "JP": "Japan", "HK": "Hong Kong", "TW": "Taiwan",
- "SG": "Singapore", "KR": "South Korea", "DE": "Germany", "GB": "United Kingdom", "FR": "France",
- "NL": "Netherlands", "CA": "Canada", "AU": "Australia", "IN": "India", "RU": "Russia",
- "BR": "Brazil", "TR": "Turkey", "VN": "Vietnam", "TH": "Thailand", "ID": "Indonesia",
- "MY": "Malaysia", "PH": "Philippines", "SE": "Sweden", "CH": "Switzerland", "IT": "Italy",
- "ES": "Spain", "PT": "Portugal", "PL": "Poland", "UA": "Ukraine", "MX": "Mexico",
- "AR": "Argentina", "CL": "Chile", "ZA": "South Africa", "AE": "UAE", "SA": "Saudi Arabia",
- "LOCAL": "Local", "UNKNOWN": "Unknown", "PRIVATE": "Private",
-};
-
-const countryNamesZh: Record<string, string> = {
- "CN": "中国", "US": "美国", "JP": "日本", "HK": "中国香港", "TW": "中国台湾",
- "SG": "新加坡", "KR": "韩国", "DE": "德国", "GB": "英国", "FR": "法国",
- "NL": "荷兰", "CA": "加拿大", "AU": "澳大利亚", "IN": "印度", "RU": "俄罗斯",
- "BR": "巴西", "TR": "土耳其", "VN": "越南", "TH": "泰国", "ID": "印度尼西亚",
- "MY": "马来西亚", "PH": "菲律宾", "SE": "瑞典", "CH": "瑞士", "IT": "意大利",
- "ES": "西班牙", "PT": "葡萄牙", "PL": "波兰", "UA": "乌克兰", "MX": "墨西哥",
- "AR": "阿根廷", "CL": "智利", "ZA": "南非", "AE": "阿联酋", "SA": "沙特阿拉伯",
- "LOCAL": "本地", "UNKNOWN": "未知", "PRIVATE": "私有",
-};
-
-function getCountryName(code: string, locale: string): string {
- const names = locale === "zh" ? countryNamesZh : countryNamesEn;
- return names[code.toUpperCase()] || code;
-}
-
export const TopCountriesSimple = React.memo(function TopCountriesSimple({
countries,
sortBy,
@@ -52,7 +26,7 @@ export const TopCountriesSimple = React.memo(function TopCountriesSimple({
isLoading,
}: TopCountriesSimpleProps) {
const t = useTranslations("topCountries");
- const locale = useLocale();
+ const countryName = useCountryName();
const itemCount = useResponsiveItemCount();
const sortedCountries = useMemo(() => {
@@ -149,8 +123,8 @@ export const TopCountriesSimple = React.memo(function TopCountriesSimple({
{index + 1}
</span>
<CountryFlag country={country.country} className="h-3.5 w-5" />
- <span className="flex-1 text-sm font-medium truncate" title={getCountryName(country.country, locale)}>
- {getCountryName(country.country, locale)}
+ <span className="flex-1 text-sm font-medium truncate" title={countryName(country.country)}>
+ {countryName(country.country)}
</span>
<span className="text-sm font-bold tabular-nums shrink-0">
{formatBytes(total)}
diff --git a/apps/web/lib/i18n-country.ts b/apps/web/lib/i18n-country.ts
new file mode 100644
index 0000000..5972d5d
--- /dev/null
+++ b/apps/web/lib/i18n-country.ts
@@ -0,0 +1,95 @@
+"use client";
+
+import { useLocale } from "next-intl";
+import { useMemo } from "react";
+
+// Special non-ISO codes used in this app
+const SPECIAL_NAMES: Record<string, Record<string, string>> = {
+ LOCAL: { en: "Local", zh: "本地" },
+ DIRECT: { en: "Direct", zh: "直连" },
+ UNKNOWN: { en: "Unknown", zh: "未知" },
+ PRIVATE: { en: "Private", zh: "私有" },
+ RESERVED: { en: "Reserved", zh: "保留" },
+};
+
+// Override CLDR defaults for specific regions to ensure consistent display
+// across different browser/OS CLDR versions
+const REGION_OVERRIDES: Record<string, Record<string, string>> = {
+ HK: { zh: "中国香港" },
+ TW: { zh: "中国台湾" },
+ MO: { zh: "中国澳门" },
+};
+
+const localeMap: Record<string, string> = {
+ zh: "zh-Hans",
+ en: "en",
+};
+
+function createDisplayNames(locale: string): Intl.DisplayNames | null {
+ try {
+ return new Intl.DisplayNames([localeMap[locale] || locale], {
+ type: "region",
+ });
+ } catch {
+ return null;
+ }
+}
+
+// Cache DisplayNames instances per locale
+const displayNamesCache = new Map<string, Intl.DisplayNames | null>();
+
+function getDisplayNames(locale: string): Intl.DisplayNames | null {
+ if (!displayNamesCache.has(locale)) {
+ displayNamesCache.set(locale, createDisplayNames(locale));
+ }
+ return displayNamesCache.get(locale)!;
+}
+
+/**
+ * Get localized country/region name from ISO 3166-1 alpha-2 code.
+ * Uses Intl.DisplayNames for standard codes and a small map for special app codes.
+ */
+export function getLocalizedCountryName(
+ code: string,
+ locale: string,
+): string {
+ if (!code) return "";
+
+ const upper = code.toUpperCase();
+
+ // Handle special non-ISO codes
+ const special = SPECIAL_NAMES[upper];
+ if (special) {
+ return special[locale] || special.en || code;
+ }
+
+ // Check overrides before CLDR (consistent across environments)
+ const override = REGION_OVERRIDES[upper];
+ if (override?.[locale]) {
+ return override[locale];
+ }
+
+ // Use Intl.DisplayNames for standard ISO country codes
+ const displayNames = getDisplayNames(locale);
+ if (displayNames) {
+ try {
+ const name = displayNames.of(upper);
+ if (name) return name;
+ } catch {
+ // Invalid code, fall through
+ }
+ }
+
+ return code;
+}
+
+/**
+ * React hook that returns a memoized country name translator for the current locale.
+ */
+export function useCountryName() {
+ const locale = useLocale();
+
+ return useMemo(() => {
+ return (code: string) => getLocalizedCountryName(code, locale);
+ }, [locale]);
+}
diff --git a/package.json b/package.json
index d42fa4b..5b1864a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "neko-master",
- "version": "1.3.4",
+ "version": "1.3.5",
"description": "Modern traffic analytics for edge gateways",
"private": true,
"workspaces": [