mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-10-21 22:29:39 +00:00
Groundwork for #1219. The menubar app hardcoded ~530 English strings across Views/, the presentation structs, the status-item menu and the update alerts, so there was nothing for a translator to translate. Every user-facing literal now goes through `L(_:)` / `L(_:_:)`, which look the string up in `Localizable.strings` in the SwiftPM target resource bundle. The key *is* the English copy, so English stays the development language and a missing translation degrades to correct English instead of a dotted identifier. `en.lproj` is therefore an identity table; it exists so the bundle advertises `en` and so a translation can be diffed against it. Why the lookups are explicit rather than relying on SwiftUI's implicit `LocalizedStringKey`: SwiftPM emits target resources into a sibling bundle (`CodeBurnMenubar_CodeBurnMenubar.bundle`) that the packaging scripts copy into `Contents/Resources`. `Bundle.main` has no `.lproj` at all, so `Text("literal")` would always miss. Naming `Bundle.module` is the one form that resolves the same way in `swift run`, in `swift test` and in the packaged `.app`. Enum raw values that double as identity (`Period`, `MenubarScope`, `InsightMode`, `AccentPreset`, `ProviderFilter`) keep their raw value and gain a `displayLabel`, so persistence and cache keys are untouched by translation. Three display-only date formatters that were pinned to `en_US_POSIX` with fixed patterns now use `setLocalizedDateFormatFromTemplate`, and the calendar popover's weekday row comes from the locale's own symbols. The `yyyy-MM-dd` formatter stays POSIX: it parses and builds data keys, not display text. Not extracted, deliberately: provider, model and plan names; units; currency codes; shell commands and paths; quota window labels that policy code matches on by English substring (`QuotaSummary.headlineWindow`); and anything the `codeburn` CLI produces. Also copies the SwiftPM resource bundle into the app in build-local.sh, using the named-bundle + `[[ -d ]]` pattern package-app.sh already uses. Without it the assembled app finds no strings table (and already trapped on first icon load, the resource-bundle half of #1262).
38 lines
1.5 KiB
Swift
38 lines
1.5 KiB
Swift
/// Shared session-count phrasing. Keep in lockstep with `src/session-count-label.ts`.
|
|
enum SessionCountLabel {
|
|
static var help: String { L("Older session logs may be unavailable.") }
|
|
/// Combined-scope counts are a per-device numeric sum with no shared identity.
|
|
/// Do not show that sum as unique or as a lower bound.
|
|
static var combinedHelp: String { L("Session identities are unavailable across devices.") }
|
|
static var combinedText: String { L("Session count unavailable") }
|
|
|
|
static func isExact(_ basis: String?) -> Bool {
|
|
basis == "identity"
|
|
}
|
|
|
|
static func text(sessions: Int, basis: String?) -> String {
|
|
if !isExact(basis) {
|
|
if sessions <= 0 { return combinedText }
|
|
return sessions == 1 ? L("At least 1 session") : L("At least %lld sessions", sessions)
|
|
}
|
|
return sessions == 1 ? L("1 session") : L("%lld sessions", sessions)
|
|
}
|
|
|
|
static func compact(sessions: Int, basis: String?) -> String {
|
|
if !isExact(basis) {
|
|
if sessions <= 0 { return L("Unavailable") }
|
|
return L("≥%lld sess", sessions)
|
|
}
|
|
return L("%lld sess", sessions)
|
|
}
|
|
|
|
static func averageText(_ value: Double?, basis: String?, format: (Double) -> String) -> String {
|
|
guard isExact(basis), let value, value.isFinite else { return "—" }
|
|
return format(value)
|
|
}
|
|
|
|
static func helpText(combined: Bool, basis: String?) -> String {
|
|
if combined { return combinedHelp }
|
|
return isExact(basis) ? "" : help
|
|
}
|
|
}
|