Skip to content

Add LocalizedStringKey + Bundle init overloads to all text-bearing OUDS components#1369

Open
Copilot wants to merge 3 commits intodevelopfrom
copilot/update-button-component-localization
Open

Add LocalizedStringKey + Bundle init overloads to all text-bearing OUDS components#1369
Copilot wants to merge 3 commits intodevelopfrom
copilot/update-button-component-localization

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

Components with text parameters only accepted String, making it impossible for library consumers to load strings from a custom Bundle (e.g., Bundle.module in a Swift Package). This adds LocalizedStringKey-based init overloads matching the SwiftUI API convention.

Changes

  • New internal helper LocalizedStringKey+keyString.swift: Mirror-based keyString extraction + resolved(tableName:bundle:) wrapping NSLocalizedString. Resolves at init time — no rendering changes needed.

  • New init overloads on all text-bearing components, each accepting (_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle = .main, comment: StaticString? = nil, ...):

    • OUDSButton (text-only, text+icon)
    • OUDSLink (text-only/icon, indicator)
    • OUDSSuggestionChip, OUDSFilterChip (text-only, icon+text)
    • OUDSChipPicker (title, all 3 selection modes)
    • OUDSBulletList.Item
    • OUDSCheckboxItem, OUDSSwitchItem, OUDSRadioItem
    • OUDSTag (label + loadingLabel via dedicated loadingKey: parameter)
    • OUDSTextInput, OUDSPasswordInput
    • OUDSAlertMessage, OUDSInlineAlert
  • CHANGELOG updated under [Unreleased]

Usage

// Before: only plain String, locked to Bundle.main
OUDSButton(text: "some_key", appearance: .strong) { }

// After: load from any bundle (e.g. a Swift Package module)
OUDSButton(LocalizedStringKey("some_key"), bundle: Bundle.module, appearance: .strong) { }
OUDSCheckboxItem(LocalizedStringKey("agree_terms"), bundle: Bundle.module, isOn: $isOn)
OUDSTextInput(LocalizedStringKey("email_label"), bundle: Bundle.module, text: $text)

All new inits delegate to the existing String-based inits after resolution, so existing validation, accessibility, and rendering logic is fully preserved.

⚠️ keyString uses Mirror reflection on LocalizedStringKey's internal structure. This is stable across known SwiftUI versions but is an implementation detail — documented in code.

Related issues

Closes #1364

Motivation & Context

Library authors embedding OUDS in a Swift Package need to load localized strings from Bundle.module, not just Bundle.main. Without this, they must pre-resolve strings manually before passing them to components.

Types of change

  • New feature (non-breaking change which adds functionality)

Previews

No UI change — API addition only.

Checklist

Contribution

Accessibility

  • My change follows accessibility good practices

Design

  • My change respects the design guidelines of Orange Unified Design System

Development

  • My change follows the developer guide
  • I checked my changes do not add new SwiftLint warnings
  • (NA) I have added unit tests to cover my changes (optional)

Documentation

  • My change introduces changes to the documentation and/or I have updated the documentation accordingly

Checklist (for Core Team only)

  • The evolution have been tested and the project builds for iPhones and iPads
  • Code review has been done by reviewers according to CODEOWNERS file
  • (NA) Design review has been done
  • (NA) Accessibility review has been done
  • (NA) Q/A team has tested the evolution
  • Documentation has been updated if relevant
  • Internal files have been updated if relevant (like CONTRIBUTING, DEVELOP, THIRD_PARTY, CONTRIBUTORS, NOTICE)
  • CHANGELOG has been updated respecting keep a changelog rules and reference the issues
  • (NA) The wiki has been updated if needed (optional)

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI linked an issue Mar 27, 2026 that may be closed by this pull request
16 tasks
Copilot AI changed the title [WIP] Update button component to use LocalizedStringKey and Bundle Add LocalizedStringKey + Bundle init overloads to all text-bearing OUDS components Mar 27, 2026
Copilot AI requested a review from pylapp March 27, 2026 17:25
Copy link
Copy Markdown
Member

@pylapp pylapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pylapp
Copy link
Copy Markdown
Member

pylapp commented Mar 30, 2026

To test, sue the design system toolbox and update MainView.swift

//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDSSwiftUI
import SwiftUI

struct MainView: View {

    @Environment(\.theme) private var theme

    var body: some View {
        OUDSTabBar(selected: 3, count: 4) {
            TokensPage()
                .tabItem {
                    Label("app_bottomBar_tokens_label", image: "design-token")
                }
                .tag(0)
            ComponentsPage()
                .tabItem {
                    Label("app_bottomBar_components_label", image: "component-atom")
                }
                .tag(1)
            AboutPage()
                .tabItem {
                    Label("app_bottomBar_about_label", image: "info-fill")
                }
                .tag(2)
            DebugPage()
                .tabItem {
                    Label("Debug", systemImage: "gear")
                }
                .tag(2)
        }.oudsAccentColor(theme.colors.contentBrandPrimary)
    }
}

struct DebugPage: View {
    
    var body: some View {
        VStack {
            // Raw string
            OUDSButton("Foo") {}
            // Local string
            OUDSButton("app_components_alert_alertMessage_closeButton_tech") {}
            // Lib string
            OUDSButton("core_checkboxPicker_indeterminate_hint_a11y", bundle: Bundle.OUDSComponents) {}
        }
    }
}

@pylapp pylapp force-pushed the copilot/update-button-component-localization branch from e30712a to c1ebbcd Compare March 30, 2026 10:43
@pylapp pylapp marked this pull request as ready for review March 30, 2026 10:45
@pylapp pylapp requested a review from ludovic35 as a code owner March 30, 2026 10:45
Copy link
Copy Markdown
Member

@pylapp pylapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pylapp
Copy link
Copy Markdown
Member

pylapp commented Mar 30, 2026

Note

@ludovic35
This pull request must be merged after the one in the Swift Package side (Orange-OpenSource/ouds-ios-design-system-toolbox#217)

Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
@pylapp pylapp force-pushed the copilot/update-button-component-localization branch from 7902f2f to cfae55f Compare March 30, 2026 11:57
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.

Use LocalizedStringKey and Bundle for components with texts

2 participants