feat(menubar): translate the Codex banked-reset copy and the cache-read tooltip

The notification, the Plan-tab detail and the hover-card line #725 added were
composed in a presentation type and shipped English to a zh-Hans user. Each is
one key now. reset_type is vendor data with no fixed vocabulary, so the four
cadence words OpenAI sends are translated and anything else rides through
verbatim inside a translated frame. compactAge stays character-identical with
the TypeScript side in English, which is what the contract was about: en is an
identity table. The dock's cache-read tooltip was bound to a let before its
call site, which is why the scan never saw it.
This commit is contained in:
iamtoruk 2026-09-12 16:12:11 -07:00
parent e53dca1350
commit d4f3d6eb7a
4 changed files with 85 additions and 25 deletions

View file

@ -111,20 +111,20 @@ enum CodexBankedResetPresentation {
/// Nil when the account holds nothing — the row hides rather than printing a zero.
static func detail(_ credits: CodexUsage.ResetCredits, now: Date) -> String? {
guard credits.availableCount > 0 else { return nil }
var parts = ["\(credits.availableCount) available"]
var parts = [L("%lld available", credits.availableCount)]
// Only worth saying when it disagrees with the headline count: equal
// numbers would just be the same fact twice.
if let applicable = credits.applicableAvailableCount, applicable != credits.availableCount {
parts.append("\(applicable) usable now")
parts.append(L("%lld usable now", applicable))
}
if let grant = credits.latestGrant, let grantedAt = grant.grantedAt {
let type = resetTypeLabel(grant.resetType)
parts.append(grantedAt > now
? "next \(type) lands \(compactAge(of: grantedAt, now: now))"
: "latest \(type) granted \(compactAge(of: grantedAt, now: now))")
? L("next %@ lands %@", type, compactAge(of: grantedAt, now: now))
: L("latest %@ granted %@", type, compactAge(of: grantedAt, now: now)))
}
if let expiry = credits.nextExpiresAt {
parts.append("next expires \(compactAge(of: expiry, now: now))")
parts.append(L("next expires %@", compactAge(of: expiry, now: now)))
}
return parts.joined(separator: " · ")
}
@ -147,45 +147,59 @@ enum CodexBankedResetPresentation {
var body: String
if let grantedAt = grant.grantedAt {
body = grantedAt > now
? "A \(type) lands \(compactAge(of: grantedAt, now: now))."
: "A \(type) was added to your account \(compactAge(of: grantedAt, now: now))."
? L("A %@ lands %@.", type, compactAge(of: grantedAt, now: now))
: L("A %@ was added to your account %@.", type, compactAge(of: grantedAt, now: now))
} else {
body = "A \(type) was added to your account."
body = L("A %@ was added to your account.", type)
}
// `applicable_available_count` is the number that answers "can I use one
// right now"; the plain count is the fallback when it is absent.
let usable = credits.applicableAvailableCount ?? credits.availableCount
body += " You have \(usable) available to use."
return ("Codex banked a limit reset", body)
body += " " + L("You have %lld available to use.", usable)
return (L("Codex banked a limit reset"), body)
}
/// "weekly" -> "weekly reset". An absent or empty `reset_type` degrades to
/// the bare noun rather than inventing a scope the payload did not state.
///
/// `reset_type` is vendor data with no fixed vocabulary, so only the cadence
/// words OpenAI has actually sent are translated; anything else rides
/// through verbatim inside a translated frame.
static func resetTypeLabel(_ resetType: String?) -> String {
let raw = (resetType ?? "")
.trimmingCharacters(in: .whitespacesAndNewlines)
.replacingOccurrences(of: "_", with: " ")
.replacingOccurrences(of: "-", with: " ")
.lowercased()
return raw.isEmpty ? "limit reset" : "\(raw) reset"
guard !raw.isEmpty else { return L("limit reset") }
let cadence = switch raw {
case "weekly": L("weekly")
case "daily": L("daily")
case "monthly": L("monthly")
case "hourly": L("hourly")
default: raw
}
return L("%@ reset", cadence)
}
/// Deliberately not `RelativeDateTimeFormatter`: this string has to come out
/// character-identical in Swift and in TypeScript, so the rules are spelled
/// out instead of delegated to a locale-aware formatter.
/// Deliberately not `RelativeDateTimeFormatter`: the English form has to
/// come out character-identical in Swift and in TypeScript, so the rules
/// are spelled out instead of delegated to a locale-aware formatter. The
/// catalog keeps that: `en` is an identity table, so English is the key.
/// Other locales diverge from the CLI, which is not localized.
static func compactAge(of date: Date, now: Date) -> String {
let elapsed = now.timeIntervalSince(date)
if elapsed >= 0 {
if elapsed < 60 { return "just now" }
if elapsed < 3600 { return "\(Int(elapsed / 60))m ago" }
if elapsed < 86_400 { return "\(Int(elapsed / 3600))h ago" }
return "\(Int(elapsed / 86_400))d ago"
if elapsed < 60 { return L("just now") }
if elapsed < 3600 { return L("%lldm ago", Int(elapsed / 60)) }
if elapsed < 86_400 { return L("%lldh ago", Int(elapsed / 3600)) }
return L("%lldd ago", Int(elapsed / 86_400))
}
let ahead = -elapsed
if ahead < 60 { return "in under a minute" }
if ahead < 3600 { return "in \(Int(ahead / 60))m" }
if ahead < 86_400 { return "in \(Int(ahead / 3600))h" }
return "in \(Int(ahead / 86_400))d"
if ahead < 60 { return L("in under a minute") }
if ahead < 3600 { return L("in %lldm", Int(ahead / 60)) }
if ahead < 86_400 { return L("in %lldh", Int(ahead / 3600)) }
return L("in %lldd", Int(ahead / 86_400))
}
}

View file

@ -693,3 +693,26 @@
"weekly usage" = "weekly usage";
"Opus weekly usage" = "Opus weekly usage";
"Sonnet weekly usage" = "Sonnet weekly usage";
/* MARK: Codex banked limit resets (#725) */
"%lld available" = "%lld available";
"%lld usable now" = "%lld usable now";
"next %@ lands %@" = "next %@ lands %@";
"latest %@ granted %@" = "latest %@ granted %@";
"next expires %@" = "next expires %@";
"A %@ lands %@." = "A %@ lands %@.";
"A %@ was added to your account %@." = "A %@ was added to your account %@.";
"A %@ was added to your account." = "A %@ was added to your account.";
"You have %lld available to use." = "You have %lld available to use.";
"Codex banked a limit reset" = "Codex banked a limit reset";
"limit reset" = "limit reset";
"%@ reset" = "%@ reset";
"daily" = "daily";
"monthly" = "monthly";
"hourly" = "hourly";
"just now" = "just now";
"%lldm ago" = "%lldm ago";
"%lldh ago" = "%lldh ago";
"%lldd ago" = "%lldd ago";
"in under a minute" = "in under a minute";
"Input tokens reused from this provider's prompt cache today — not fresh input (arrow.down), not cache writes, and already priced at the cache-read rate inside the burned figure." = "Input tokens reused from this provider's prompt cache today — not fresh input (arrow.down), not cache writes, and already priced at the cache-read rate inside the burned figure.";

View file

@ -685,3 +685,26 @@
"weekly usage" = "每周用量";
"Opus weekly usage" = "Opus 每周用量";
"Sonnet weekly usage" = "Sonnet 每周用量";
/* MARK: Codex banked limit resets (#725) */
"%lld available" = "%lld 个可用";
"%lld usable now" = "%lld 个现在可用";
"next %@ lands %@" = "下一次%@将于 %@ 到账";
"latest %@ granted %@" = "最近一次%@于 %@ 发放";
"next expires %@" = "下一个将于 %@ 过期";
"A %@ lands %@." = "一次%@将于 %@ 到账。";
"A %@ was added to your account %@." = "%@ 已于 %@ 添加到你的账户。";
"A %@ was added to your account." = "%@ 已添加到你的账户。";
"You have %lld available to use." = "你有 %lld 个可以使用。";
"Codex banked a limit reset" = "Codex 存入了一次限额重置";
"limit reset" = "限额重置";
"%@ reset" = "%@重置";
"daily" = "每日";
"monthly" = "每月";
"hourly" = "每小时";
"just now" = "刚刚";
"%lldm ago" = "%lld 分钟前";
"%lldh ago" = "%lld 小时前";
"%lldd ago" = "%lld 天前";
"in under a minute" = "不到一分钟后";
"Input tokens reused from this provider's prompt cache today — not fresh input (arrow.down), not cache writes, and already priced at the cache-read rate inside the burned figure." = "今天从该服务商提示缓存中复用的输入 Token。不是新的输入(arrow.down),也不是缓存写入,并且已按缓存读取费率计入已消耗金额。";

View file

@ -1129,9 +1129,9 @@ struct CapacityDockDetailView: View {
@ViewBuilder
private func cacheReadLine(_ value: Double) -> some View {
let s = model.detailScale
let explanation = "Input tokens reused from this provider's prompt cache today — "
+ "not fresh input (arrow.down), not cache writes, and already priced at the "
+ "cache-read rate inside the burned figure."
let explanation = L(
"Input tokens reused from this provider's prompt cache today — not fresh input (arrow.down), not cache writes, and already priced at the cache-read rate inside the burned figure."
)
HStack(spacing: 4 * s) {
Image(systemName: "arrow.triangle.2.circlepath")
.font(.system(size: 9, weight: .semibold))