Skip to content

Localize string literal titles of HPicker and VPicker - #28

Open
Jeehut wants to merge 1 commit into
mainfrom
wip/hpicker-title-localization
Open

Jeehut wants to merge 1 commit into
mainfrom
wip/hpicker-title-localization

Conversation

@Jeehut

@Jeehut Jeehut commented Nov 21, 2026

Copy link
Copy Markdown
Member

HPicker("Pomodoro Length", locked: [], selection: $value) showed the title untranslated. A string literal matched the String initializer, which builds a plain Text(title) from a String value, so no localization lookup happened. FocusBeats works around this with a custom Text label (OptionsWizardView.swift:242).

The String initializers of HPicker and VPicker are now @_disfavoredOverload, the same way SwiftUI's own Text.init<S: StringProtocol> is marked. A literal now picks the LocalizedStringKey initializer and gets translated. A String variable still uses the String initializer and is shown as is. No call site has to change. The doc comments say which initializer does what.

Considered: removing the String initializers. Rejected, because callers that pass already localized String values (CrossCraft does) would break.

How this was verified

  • Red on main (589e450): a test comparing the picker title with Text(LocalizedStringKey) failed, the title was .verbatim("Fruit"). A control test showed the comparison really tells localized and verbatim Text apart.
  • Green on the branch: swift test --build-system swiftbuild, 43 tests in 13 suites passed. Also built for iOS with xcodebuild.
  • Not checked: FocusBeats itself with this branch. Review: Code ✓ · Design – · QA –

Door two-way · Blast Radius breit (public API, re-exported by FlineDevKit)

Both pickers have a title initializer for a LocalizedStringKey and one
for a String. For a string literal Swift prefers the String overload,
which builds a verbatim Text. So a title like "Pomodoro Length" never
found the app's translations and always showed the English key.

Mark the String initializers as disfavored, the same way SwiftUI does
for Text, so literals pick the LocalizedStringKey initializer while a
String value still shows as is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant