Skip to content

Use LocalizedStringKey and Bundle for components with texts #1366

@pylapp

Description

@pylapp

Context

Today, for example for a button component, users initialize it with a value given as a string parameter like:

OUDSButton(text: "Some text", appearance: .strong) { /* the action to process */ }

However even if it works well for an app, there are limitations if users use OUDS inside libraries: they may want to load a string from another Bundle than main.

Issue

Today if a user wants to display a string to load as a localizable, he must use the dedicated Swift API, a bit long with something like Bundle.module.localized...

Proposal

Update API of components to be aligned with SwiftUI API and let user define the bundle to use.

For example, the button component will be also like:

OUDSButton(LocalizedStringKey("some_key), bundle: Bundle.module, appearance: .strong) { /* the action to process */ }

The API should be enriched like:

// First API
public init(text: String,
                  icon: Image,
                  flipIcon: Bool = false,
                  appearance: Appearance = .default,
                  style: Style = .default,
                  isFullWidth: Bool = false,
                  action: @escaping () -> Void) {}

// New API
public init(_ key: LocalizedStringKey,
                  tableName: String? = nil,
                  bundle: Bundle = Bundle.main,
                  comment: StaticString? = nil,
                  icon: Image,
                  flipIcon: Bool = false,
                  appearance: Appearance = .default,
                  style: Style = .default,
                  isFullWidth: Bool = false,
                  action: @escaping () -> Void) {}

Definition of Done

  • Enrich API of OUDSButton
  • Enrich API of OUDSCheckboxItem
  • Enrich API of OUDSSwitchItem
  • Enrich API of OUDSRadioItem
  • Enrich API of OUDSBulletList.item
  • Enrich API of OUDSSuggestionChip
  • Enrich API of OUDSFilterChip
  • Enrich API of OUDSChipPicker
  • Enrich API of OUDSLink
  • Enrich API of OUDSPassWordInput
  • Enrich API of OUDSTag
  • Enrich API of OUDSTextInput
  • Enrich API of OUDSAlertMessage
  • Enrich API of OUDSInlineAlert
  • Update CHANGELOG
  • For all modifier components update Swift DocC documentation with one example about use of LocalizedStringKey and bundle

Discussed in #1364

Originally posted by fsuc March 27, 2026

  • if OUDS is used in a library and in the app, the OUDSThemeableView can be used several times.
  • In my case, with OUDS just in my library, I needed to add another view to include the OUDSThemeableView. Without that, the view was created several times (body recompute).
  • It should be nice to add a convenience init for the OUDSButton to pass localized key located into another bundle

Metadata

Metadata

Assignees

Labels

#️⃣ REX and feebacksAfterr discussions with returns of experiences and feedbacks from users⌛ waiting for code reviewThe issue is implemented and the associated pull request must be reviewed by developers⚛️ componentRelated to a component provided by the library🧑‍💻 Developer eXperienceRelated to improvements of developer experience thanks to feedbacks)🧰 library

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions