From 36518d29dbcde80d1a68ecc4a49f27ab01e6a231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Mon, 16 Nov 2026 00:17:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E6=A0=A1=E6=AD=A3=E4=B8=89=E8=AF=AD?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E6=96=87=E6=A1=88=E5=B9=B6=E6=A0=B8=E5=AF=B9?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=8C=85=E8=AF=91=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/monitoring.md | 2 +- docs/testing.md | 2 +- .../MenuBar/MenuPanelView+ResourceCards.swift | 5 +- kymo/Features/MenuBar/MenuPanelView.swift | 3 +- kymo/Features/MenuBar/PowerResourceCard.swift | 6 +- .../Features/MenuBar/StorageDetailsView.swift | 17 +- kymo/Resources/Localizable.xcstrings | 146 +++++++++++++++--- kymoTests/LocalizationCatalogChecks.py | 20 ++- kymoTests/LocalizationChecks.swift | 7 +- tools/check.py | 2 +- 10 files changed, 172 insertions(+), 38 deletions(-) diff --git a/docs/monitoring.md b/docs/monitoring.md index 65dc250..78bfdf4 100644 --- a/docs/monitoring.md +++ b/docs/monitoring.md @@ -41,7 +41,7 @@ CPU / GPU / 电量的零值与 100% 分别映射到卡片底边和顶边,内 - GPU Renderer / Tiler 是活动阶段指标,可能重叠,不能相加成为总占用。GPU 核心数不代表逐核计数;目前没有独立逐核 GPU 占用。 - 网络“全部”仅汇总 active 且名称以 `en` 开头的接口,避免物理链路与 `utun` 双计。接口选择仍可查看其他活动接口;这个规则不等于所有设备和隧道的通用流量归因。 - 进程 CPU 以一个逻辑核满载为 100%,多线程可超过 100%,不能直接与整机 CPU 百分比比较。首次进程采样没有差分值;功率列使用独立 CPU 能量计数差分,不能将进程 CPU 百分比当成耗电。 -- 电池卡片仅在非外接电源时显示剩余时间;外接电源显示不适用,系统未给出有效估计时显示未知。 +- 电池卡片在系统报告充电时显示距充满的估时,电池供电时显示剩余续航。外接供电且未充电时显示不适用,系统未提供有效估时则显示相应提示。 ## 采样与缓存周期 diff --git a/docs/testing.md b/docs/testing.md index 2c3a878..b9734e3 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -52,7 +52,7 @@ python3 tools/check.py --list | ReleaseServiceChecks(--services) | 临时 hardened sandbox 主程序调用本轮实际嵌入服务,核对同 UID footprint / 能量与传感器,并输出本机 B0AP 带符号瓦数或不可用状态 | | SandboxNetworkChecks(--network) | 使用实际主应用 entitlement 访问产品 HTTPS 端点,核对持久网络目录无新增或变更文件 | -LocalizationCatalogChecks.py 检查全部保留键的三语完整性与格式参数,不替代翻译语义和实际排版。服务 / 网络不可达也会使对应检查失败。 +LocalizationCatalogChecks.py 检查全部词条的三语完整性与格式参数。统一检查入口还逐项比对构建包内四份字符串表与源译文;翻译语义和实际排版需另行核对。服务 / 网络不可达也会使对应检查失败。 ## 实际应用验收 diff --git a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift index b644ba9..80ca2d4 100644 --- a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift +++ b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift @@ -48,7 +48,8 @@ extension MenuPanelView { return ResourceCard( title: "metric.gpu", symbol: "square.grid.2x2", color: Color("MetricGPU"), value: MetricFormat.percent(snapshot.gpuUsage), titleBadge: snapshot.gpu?.coreCount.map { - String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), $0) + $0 == 1 ? AppLocalization.string("gpu.oneCore", locale: locale) + : String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), $0) }, status: snapshot.gpuTemperature.map { "\(Int($0.rounded()))°C" }, chartPlacement: .background, @@ -110,7 +111,7 @@ extension MenuPanelView { second: samples.map(\.memoryApp), third: samples.map(\.memoryWired), fourth: samples.map(\.memoryCompressed), color: Color("MemoryApplication"), secondColor: Color("MemoryApplication"), thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1), - firstValueFormat: .memory, firstLabel: "gpu.totalUtilization", + firstValueFormat: .memory, firstLabel: "memory.used", secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, stackOrder: [1, 2, 3]) } diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index bf52cd2..0b38e4b 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -162,7 +162,8 @@ struct MenuPanelView: View { HStack { HStack(spacing: 4) { Text("panel.uptime") - MetricText(value: String(format: "%.1f h", snapshot.uptime / 3600)) + let hours = (snapshot.uptime / 3600).formatted(.number.precision(.fractionLength(1)).grouping(.never).locale(locale)) + Text("duration.hours \(hours)").monospacedDigit() }.fixedSize() Divider().frame(height: 14) Text(verbatim: HardwareIdentity.displayName) diff --git a/kymo/Features/MenuBar/PowerResourceCard.swift b/kymo/Features/MenuBar/PowerResourceCard.swift index ce4710b..1664b4c 100644 --- a/kymo/Features/MenuBar/PowerResourceCard.swift +++ b/kymo/Features/MenuBar/PowerResourceCard.swift @@ -105,10 +105,10 @@ struct PowerResourceCard: View { InlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--") } HStack(spacing: 4) { - Text("battery.timeShort").foregroundStyle(.secondary) + Text(battery.flow.charging == true ? "battery.timeToFull" : "battery.timeShort").foregroundStyle(.secondary) if let minutes = battery.minutesRemaining { - MetricText(value: "\(minutes) min") - } else if battery.flow.state == .external { + Text("duration.minutes \(minutes)").monospacedDigit() + } else if battery.flow.state == .external && battery.flow.charging != true { Text("battery.notApplicableShort").help(Text("battery.timeNotApplicable")) } else { Text("battery.timeUnknown") diff --git a/kymo/Features/MenuBar/StorageDetailsView.swift b/kymo/Features/MenuBar/StorageDetailsView.swift index a328b22..ead8caa 100644 --- a/kymo/Features/MenuBar/StorageDetailsView.swift +++ b/kymo/Features/MenuBar/StorageDetailsView.swift @@ -7,7 +7,7 @@ struct StorageDetailsView: View { var body: some View { VStack(alignment: .leading, spacing: 3) { - field("memory.available", value: MetricFormat.bytes(disk?.available)) + field("memory.available", value: Text(verbatim: MetricFormat.bytes(disk?.available))) ViewThatFits(in: .horizontal) { HStack(spacing: 6) { read; write }.fixedSize(horizontal: true, vertical: true) VStack(alignment: .leading, spacing: 3) { read; write } @@ -24,15 +24,18 @@ struct StorageDetailsView: View { .font(.system(size: 10)).lineLimit(1) } - private var read: some View { field("disk.read", value: MetricFormat.rate(io?.read)) } - private var write: some View { field("disk.write", value: MetricFormat.rate(io?.written)) } - private var life: some View { field("disk.lifeShort", value: MetricFormat.percent(health?.remainingLife)) } - private var powerOn: some View { field("disk.powerOnShort", value: health?.powerOnHours.map { "\($0) h" } ?? "--") } + private var read: some View { field("disk.read", value: Text(verbatim: MetricFormat.rate(io?.read))) } + private var write: some View { field("disk.write", value: Text(verbatim: MetricFormat.rate(io?.written))) } + private var life: some View { field("disk.lifeShort", value: Text(verbatim: MetricFormat.percent(health?.remainingLife))) } + private var powerOn: some View { + let hours = health?.powerOnHours.map { Text("duration.hours \(String($0))") } + return field("disk.powerOnShort", value: hours ?? Text(verbatim: "--")) + } - private func field(_ title: LocalizedStringKey, value: String) -> some View { + private func field(_ title: LocalizedStringKey, value: Text) -> some View { HStack(spacing: 3) { Text(title).foregroundStyle(.secondary).help(Text(title)) - MetricText(value: value).fontWeight(.medium).foregroundStyle(.primary) + value.monospacedDigit().fontWeight(.medium).foregroundStyle(.primary) }.frame(height: 14) } } diff --git a/kymo/Resources/Localizable.xcstrings b/kymo/Resources/Localizable.xcstrings index 4c1e6e3..2c957a9 100644 --- a/kymo/Resources/Localizable.xcstrings +++ b/kymo/Resources/Localizable.xcstrings @@ -1,6 +1,94 @@ { "sourceLanguage" : "en", "strings" : { + "duration.hours %@": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "%@ h" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "%@ 小时" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "%@ 小時" + } + } + } + }, + "duration.minutes %lld": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "%lld min" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "%lld 分钟" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "%lld 分鐘" + } + } + } + }, + "memory.used": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Memory used" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "已用内存" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "已用記憶體" + } + } + } + }, + "gpu.oneCore": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "1 core" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "1 核" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "1 核心" + } + } + } + }, "power.charging": { "localizations": { "en": { @@ -238,7 +326,7 @@ "zh-Hant": { "stringUnit": { "state": "translated", - "value": "應用包含應用和系統程序使用的匿名記憶體;連動包含核心、驅動等常駐記憶體;壓縮為壓縮器的實際實體佔用。可回收快取計入可用空間,磁碟 Swap 不再疊加到實體記憶體已用量。" + "value": "App 記憶體包含 App 與系統程序使用的匿名記憶體。系統核心記憶體包含核心與驅動程式等必須常駐的記憶體。壓縮欄顯示壓縮後實際佔用的實體記憶體。可回收的快取計入可用記憶體,磁碟上的交換空間另計。" } } } @@ -270,7 +358,7 @@ "en": { "stringUnit": { "state": "translated", - "value": "On-time" + "value": "Power-on" } }, "zh-Hans": { @@ -336,19 +424,41 @@ "en": { "stringUnit": { "state": "translated", - "value": "Time" + "value": "Time left" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "估时" + "value": "剩余时间" } }, "zh-Hant": { "stringUnit": { "state": "translated", - "value": "估時" + "value": "剩餘時間" + } + } + } + }, + "battery.timeToFull" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Time to full" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "距充满" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "距充滿" } } } @@ -392,7 +502,7 @@ "zh-Hant": { "stringUnit": { "state": "translated", - "value": "應用" + "value": "App" } } } @@ -414,7 +524,7 @@ "zh-Hant": { "stringUnit": { "state": "translated", - "value": "連動" + "value": "系統核心" } } } @@ -1678,19 +1788,19 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Measured intervals / enumerated processes: %1$lld / %2$lld" + "value" : "Processes with a CPU power reading: %1$lld of %2$lld enumerated" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "有效区间进程数 / 枚举数:%1$lld / %2$lld" + "value" : "已测得 CPU 功率的进程:%1$lld / %2$lld" } }, "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "有效區間程序數 / 列舉數:%1$lld / %2$lld" + "value" : "已測得 CPU 功率的程序:%1$lld / %2$lld" } } } @@ -1828,7 +1938,7 @@ "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "%d 核" + "value" : "%d 核心" } } } @@ -2051,7 +2161,7 @@ "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "應用程式記憶體" + "value" : "App 記憶體" } } } @@ -2212,7 +2322,7 @@ "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "連動記憶體" + "value" : "系統核心記憶體" } } } @@ -2623,19 +2733,19 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "APFS volumes may share capacity; do not add totals." + "value" : "APFS volumes may share capacity. Summing them can count the same space twice." } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "APFS 卷可能共享容量,不合算总量。" + "value" : "APFS 卷可能共享容量,直接相加会重复计算。" } }, "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "APFS 卷宗可能共用容量,不加總。" + "value" : "APFS 卷宗可能共用容量,直接加總會重複計算。" } } } @@ -3157,13 +3267,13 @@ "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "开机时间" + "value" : "运行时长" } }, "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "開機時間" + "value" : "運作時間" } } } diff --git a/kymoTests/LocalizationCatalogChecks.py b/kymoTests/LocalizationCatalogChecks.py index 5b25499..1e3bba3 100644 --- a/kymoTests/LocalizationCatalogChecks.py +++ b/kymoTests/LocalizationCatalogChecks.py @@ -1,8 +1,10 @@ -"""Validate catalog coverage and printf argument compatibility against zh-Hans.""" +"""Validate catalog coverage and printf argument compatibility in the source catalogs and optionally the compiled app.""" +import argparse import collections import json from pathlib import Path import re +import subprocess root = Path(__file__).resolve().parents[1] / 'kymo/Resources' pattern = re.compile(r'%(?:(\d+)\$)?[-+#0 ]*(?:\d+)?(?:\.\d+)?(ll|l|h)?([@diuoxXfFeEgGcCsSp])') @@ -13,13 +15,25 @@ def arguments(text): result[(int(match[1] or index), (match[2] or '') + match[3])] += 1 return result +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument('--app', type=Path, help='Also compare every translation with the built app') +app = parser.parse_args().app +locales = ('zh-Hans', 'en', 'zh-Hant') count = 0 for path in sorted(root.glob('*.xcstrings')): + compiled = {} + if app: + for locale in locales: + table = app / 'Contents' / 'Resources' / f'{locale}.lproj' / f'{path.stem}.strings' + compiled[locale] = json.loads(subprocess.check_output(['plutil', '-convert', 'json', '-o', '-', table])) for key, entry in json.loads(path.read_text())['strings'].items(): units = {locale: entry['localizations'][locale]['stringUnit'] - for locale in ['zh-Hans', 'en', 'zh-Hant']} + for locale in locales} + expected = arguments(key) or arguments(units['en']['value']) for locale, unit in units.items(): assert unit['state'] == 'translated' and unit['value'].strip(), (path, key, locale) - assert arguments(unit['value']) == arguments(units['zh-Hans']['value']), (path, key, locale) + assert arguments(unit['value']) == expected, (path, key, locale) + if app: + assert compiled[locale].get(key) == unit['value'], (path, key, locale, 'built translation') count += 1 print(f'PASS: {count} catalog entries, three-language coverage and format arguments') diff --git a/kymoTests/LocalizationChecks.swift b/kymoTests/LocalizationChecks.swift index ac805ca..a488f7a 100644 --- a/kymoTests/LocalizationChecks.swift +++ b/kymoTests/LocalizationChecks.swift @@ -36,7 +36,12 @@ import Foundation let expected = ["en": "Fan", "zh-Hans": "风扇", "zh-Hant": "風扇"][language]! precondition(title == "\(expected) \(number)", "Numbered fan must use the selected app locale") } - + let minutes = AppLocalization.string("duration.minutes %lld", locale: locale, bundle: bundle) + let hours = AppLocalization.string("duration.hours %@", locale: locale, bundle: bundle) + let durations = [String(format: minutes, Int64(45)), String(format: hours, "1.5")] + let expectedDurations = ["en": ["45 min", "1.5 h"], "zh-Hans": ["45 分钟", "1.5 小时"], + "zh-Hant": ["45 分鐘", "1.5 小時"]] + precondition(durations == expectedDurations[language]) } print("PASS: system matching, explicit override, fallback, preference roundtrip, built three-language resources") } diff --git a/tools/check.py b/tools/check.py index 9f248eb..37d9731 100644 --- a/tools/check.py +++ b/tools/check.py @@ -199,7 +199,7 @@ def main(): print(line, flush=True) app = work / "build/Build/Products" / args.configuration / "kymo.app" host_entitlements = entitlements(app) - run([sys.executable, "kymoTests/LocalizationCatalogChecks.py"]) + run([sys.executable, "kymoTests/LocalizationCatalogChecks.py", "--app", app]) for index, name in enumerate(selected, 1): print(f"[{index}/{len(selected)}] {name}", flush=True) executable = work / name