Files
OpenStats/Packages/OpenStatsKit/Sources/OpenStatsUI/Design/GeoText.swift
T
gentpan 645d161cbd 清理死代码、死译文与重复代码
- 删掉没人调用的函数、属性与解码字段:网络弹窗的两个标签函数、supportsStyleOverride、probedAddress、countryEn、辅助工具客户端的单风扇恢复自动封装(协议与辅助工具端保留,不动 XPC 接口)
- 译文表删掉 19 条不再使用的条目,补上测速窗口“开始”按钮漏掉的英文
- 网络弹窗与出口窗口各自一份的归属地格式化和 IP 类型徽章合并为 GeoText;两个折线图里重复的参考线绘制提成 ChartGrid
- 官网样式删掉没人用的 .mb-drop__ext
- server/sync/sync 是误提交的 Go 编译产物,从仓库移除并忽略
2026-09-21 03:38:08 +05:00

26 lines
1.5 KiB
Swift

import Foundation
import Localization
/// 归属地与 IP 类型的文字:网络弹窗与出口窗口共用
enum GeoText {
/// 国家 · 省 / 州 · 城市;英文界面优先用英文地名,重复的相邻项只留一个
static func location(countryCode: String, region: String?, regionEnglish: String?, city: String?, cityEnglish: String?) -> String {
let country = Locale(identifier: L10n.isEnglish ? "en" : "zh-Hans").localizedString(forRegionCode: countryCode) ?? countryCode
let region = L10n.isEnglish ? (regionEnglish ?? region) : region
let city = L10n.isEnglish ? (cityEnglish ?? city) : city
var parts = [country]
for part in [region, city].compactMap({ $0 }) where part != parts.last { parts.append(part) }
return parts.joined(separator: " · ")
}
/// 数据源给的 IP 类型(residential ip、datacenter ip……)对应的徽章;不认识的返回 nil
static func ipTypeBadge(_ raw: String) -> (icon: String, text: String, tone: TagBadge.Tone)? {
let type = raw.lowercased()
if type.contains("residential") { return ("house.fill", tr("住宅 IP"), .success) }
if type.contains("mobile") { return ("iphone.radiowaves.left.and.right", tr("移动网络 IP"), .success) }
if type.contains("business") { return ("building.2.fill", tr("企业 IP"), .success) }
if type.contains("idc") || type.contains("datacenter") || type.contains("hosting") { return ("server.rack", tr("机房 IP"), .warning) }
return nil
}
}