codeburn/mac/Package.swift
ozymandiashh d62857ea4e feat(menubar): route every user-facing string through a strings catalog
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).
2026-09-12 15:21:49 -07:00

51 lines
2.1 KiB
Swift

// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "CodeBurnMenubar",
// English is the development language: every key in Localizable.strings *is*
// its English copy, so a key with no translation renders as correct English
// instead of a dotted identifier. Declaring it here is also what lets SwiftPM
// treat Resources/<locale>.lproj as localized resources at all.
defaultLocalization: "en",
platforms: [
// macOS 14 (Sonoma) is the floor: matches Info.plist LSMinimumSystemVersion,
// the CLI install guard (MIN_MACOS_MAJOR=14), and mac/README. The earlier .v15
// bump for NSAttributedString(attachment:) was a misdiagnosis, that initializer
// is AppKit since macOS 10.0, so the binary's minos must not exclude Sonoma users.
.macOS(.v14)
],
products: [
.executable(name: "CodeBurnMenubar", targets: ["CodeBurnMenubar"])
],
targets: [
.executableTarget(
name: "CodeBurnMenubar",
path: "Sources/CodeBurnMenubar",
resources: [
.process("Resources/ProviderIcons"),
// Emitted into the target resource bundle as `<locale>.lproj/
// Localizable.strings`, which is the layout NSBundle needs to
// resolve a table per localization. Lookups go through
// `L(_:)` / `Bundle.module`, never `Bundle.main`: the strings
// live in the SwiftPM resource bundle inside Contents/Resources,
// not at the app bundle's resource root.
.process("Resources/en.lproj")
],
swiftSettings: [
.enableUpcomingFeature("StrictConcurrency")
],
linkerSettings: [
.linkedLibrary("sqlite3")
]
),
.testTarget(
name: "CodeBurnMenubarTests",
dependencies: ["CodeBurnMenubar"],
path: "Tests/CodeBurnMenubarTests",
linkerSettings: [
.linkedLibrary("sqlite3")
]
)
]
)