Skip to content

Commit ef35cec

Browse files
Copilotpylapp
andcommitted
Add LocalizedStringKey and Bundle init overloads to all text-bearing OUDS components
Agent-Logs-Url: https://github.com/Orange-OpenSource/ouds-ios/sessions/5afc98de-b850-404a-9a71-2a015b99c709 Co-authored-by: pylapp <7559007+pylapp@users.noreply.github.com>
1 parent e991c9d commit ef35cec

File tree

16 files changed

+799
-0
lines changed

16 files changed

+799
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased](https://github.com/Orange-OpenSource/ouds-ios/compare/1.3.0...develop)
88

9+
### Added
10+
11+
- `LocalizedStringKey` and `Bundle` initializers for `OUDSButton`, `OUDSLink`, `OUDSSuggestionChip`, `OUDSFilterChip`, `OUDSChipPicker`, `OUDSBulletList.Item`, `OUDSCheckboxItem`, `OUDSSwitchItem`, `OUDSRadioItem`, `OUDSTag`, `OUDSTextInput`, `OUDSPasswordInput`, `OUDSAlertMessage` and `OUDSInlineAlert` components (Orange-OpenSource/ouds-ios#1364)
12+
913
## [1.3.0](https://github.com/Orange-OpenSource/ouds-ios/compare/1.2.0...1.3.0) - 2026-03-26
1014

1115
### Added

OUDS/Core/Components/Sources/Actions/Button/OUDSButton.swift

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,43 @@ public struct OUDSButton: View {
196196
self.style = style
197197
self.isFullWidth = isFullWidth
198198
self.action = action
199+
isHover = false
200+
}
199201

202+
/// Creates a button with a localized text and icon, looking up the key in the given bundle.
203+
///
204+
/// ```swift
205+
/// OUDSButton(LocalizedStringKey("validate_button"), bundle: Bundle.module, icon: Image("ic_checkmark"), appearance: .strong) { }
206+
/// ```
207+
///
208+
/// - Parameters:
209+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
210+
/// - tableName: The name of the `.strings` file, or `nil` for the default
211+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
212+
/// - comment: An optional comment for translators, does not affect the resolved value
213+
/// - icon: An image which shoud contains an icon
214+
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
215+
/// - appearance: The button appearance, default set to `.default`
216+
/// - style: The button style, default set to `.default`
217+
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
218+
/// - action: The action to perform when the user triggers the button
219+
public init(_ key: LocalizedStringKey,
220+
tableName: String? = nil,
221+
bundle: Bundle = .main,
222+
comment: StaticString? = nil,
223+
icon: Image,
224+
flipIcon: Bool = false,
225+
appearance: Appearance = .default,
226+
style: Style = .default,
227+
isFullWidth: Bool = false,
228+
action: @escaping () -> Void)
229+
{
230+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
231+
type = .textAndIcon(text: resolvedText, icon: icon, flipIcon: flipIcon)
232+
self.appearance = appearance
233+
self.style = style
234+
self.isFullWidth = isFullWidth
235+
self.action = action
200236
isHover = false
201237
}
202238

@@ -248,6 +284,39 @@ public struct OUDSButton: View {
248284
isHover = false
249285
}
250286

287+
/// Creates a button with a localized text only, looking up the key in the given bundle.
288+
///
289+
/// ```swift
290+
/// OUDSButton(LocalizedStringKey("delete_button"), bundle: Bundle.module, appearance: .negative) { }
291+
/// ```
292+
///
293+
/// - Parameters:
294+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
295+
/// - tableName: The name of the `.strings` file, or `nil` for the default
296+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
297+
/// - comment: An optional comment for translators, does not affect the resolved value
298+
/// - appearance: The button appearance, default set to `.default`
299+
/// - style: The button style, default set to `.default`
300+
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
301+
/// - action: The action to perform when the user triggers the button
302+
public init(_ key: LocalizedStringKey,
303+
tableName: String? = nil,
304+
bundle: Bundle = .main,
305+
comment: StaticString? = nil,
306+
appearance: Appearance = .default,
307+
style: Style = .default,
308+
isFullWidth: Bool = false,
309+
action: @escaping () -> Void)
310+
{
311+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
312+
type = .text(resolvedText)
313+
self.appearance = appearance
314+
self.style = style
315+
self.action = action
316+
self.isFullWidth = isFullWidth
317+
isHover = false
318+
}
319+
251320
// MARK: Body
252321

253322
// swiftlint:disable line_length

OUDS/Core/Components/Sources/ContentDisplay/BulletList/OUDSBulletList.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ public struct OUDSBulletList: View {
195195
self.subListHasBoldText = subListHasBoldText
196196
self.subItems = subItems()
197197
}
198+
199+
/// Creates a bullet list item with a localized text, looking up the key in the given bundle.
200+
///
201+
/// ```swift
202+
/// OUDSBulletList.Item(LocalizedStringKey("item_label"), bundle: Bundle.module)
203+
/// ```
204+
///
205+
/// - Parameters:
206+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
207+
/// - tableName: The name of the `.strings` file, or `nil` for the default
208+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
209+
/// - comment: An optional comment for translators, does not affect the resolved value
210+
/// - subListType: The specific `OUDSBulletList.Type` for the nested sub-list, if any. If `nil`,
211+
/// the type is inherited from the parent list.
212+
/// - subListTextStyle: The specific `OUDSBulletList.TextStyle` for the nested sub-list, if any. If
213+
/// `nil`, the text style is inherited from the parent list.
214+
/// - subListHasBoldText: Whether the text of the nested sub-list should be bold. If `nil`, the bold
215+
/// setting is inherited from the parent list.
216+
/// - subItems: The sub items builder to add to the current item. **Remark** only three levels are allowed.
217+
public init(_ key: LocalizedStringKey,
218+
tableName: String? = nil,
219+
bundle: Bundle = .main,
220+
comment: StaticString? = nil,
221+
subListType: OUDSBulletList.`Type`? = nil,
222+
subListTextStyle: OUDSBulletList.TextStyle? = nil,
223+
subListHasBoldText: Bool? = nil,
224+
@OUDSBulletListItemBuilder subItems: () -> [OUDSBulletList.Item] = { [] })
225+
{
226+
text = key.resolved(tableName: tableName, bundle: bundle)
227+
self.subListType = subListType
228+
self.subListTextStyle = subListTextStyle
229+
self.subListHasBoldText = subListHasBoldText
230+
self.subItems = subItems()
231+
}
198232
}
199233

200234
// swiftlint:enable discouraged_optional_boolean

OUDS/Core/Components/Sources/Controls/Checkbox/OUDSCheckboxItem.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,60 @@ public struct OUDSCheckboxItem: View {
294294
self.action = action
295295
}
296296

297+
/// Creates a checkbox with a localized label, looking up the key in the given bundle.
298+
///
299+
/// ```swift
300+
/// OUDSCheckboxItem(LocalizedStringKey("agree_terms"), bundle: Bundle.module, isOn: $isOn)
301+
/// ```
302+
///
303+
/// **The design system does not allow to have both an error situation and a read only mode for the component.**
304+
///
305+
/// - Parameters:
306+
/// - key: A `LocalizedStringKey` used to look up the label in the given bundle
307+
/// - tableName: The name of the `.strings` file, or `nil` for the default
308+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
309+
/// - comment: An optional comment for translators, does not affect the resolved value
310+
/// - isOn: A binding to a property that determines whether the indicator is ticked (selected) or not (unselected)
311+
/// - description: An additional helper text, a description, which should not be empty, default set to `nil`
312+
/// - icon: An optional icon, default set to `nil`
313+
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
314+
/// - isReversed: `true` if the checkbox indicator must be in trailing position, `false` otherwise. Default to `false`
315+
/// - isError: `true` if the look and feel of the component must reflect an error state, default set to `false`
316+
/// - errorText: An optional error message to display at the bottom. This message is ignored if `isError` is `false`.
317+
/// - isReadOnly: True if component is in read only, default set to `false`
318+
/// - hasDivider: If `true` a divider is added at the bottom of the view, by default set to `false`
319+
/// - constrainedMaxWidth: When `true`, the item width is constrained to a maximum value defined by the design system.
320+
/// - action: An additional action to trigger when the checkbox has been pressed
321+
public init(_ key: LocalizedStringKey,
322+
tableName: String? = nil,
323+
bundle: Bundle = .main,
324+
comment: StaticString? = nil,
325+
isOn: Binding<Bool>,
326+
description: String? = nil,
327+
icon: Image? = nil,
328+
flipIcon: Bool = false,
329+
isReversed: Bool = false,
330+
isError: Bool = false,
331+
errorText: String? = nil,
332+
isReadOnly: Bool = false,
333+
hasDivider: Bool = false,
334+
constrainedMaxWidth: Bool = false,
335+
action: (() -> Void)? = nil)
336+
{
337+
self.init(key.resolved(tableName: tableName, bundle: bundle),
338+
isOn: isOn,
339+
description: description,
340+
icon: icon,
341+
flipIcon: flipIcon,
342+
isReversed: isReversed,
343+
isError: isError,
344+
errorText: errorText,
345+
isReadOnly: isReadOnly,
346+
hasDivider: hasDivider,
347+
constrainedMaxWidth: constrainedMaxWidth,
348+
action: action)
349+
}
350+
297351
// MARK: Body
298352

299353
public var body: some View {

OUDS/Core/Components/Sources/Controls/Chip/OUDSFilterChip.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,37 @@ public struct OUDSFilterChip: View {
8282
self.selected = selected
8383
}
8484

85+
/// Creates a filter chip with a localized text and icon, looking up the key in the given bundle.
86+
///
87+
/// ```swift
88+
/// OUDSFilterChip(icon: Image("ic_heart"), LocalizedStringKey("like_filter"), bundle: Bundle.module, selected: true) { }
89+
/// ```
90+
///
91+
/// - Parameters:
92+
/// - icon: An image which shoud contains an icon
93+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
94+
/// - tableName: The name of the `.strings` file, or `nil` for the default
95+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
96+
/// - comment: An optional comment for translators, does not affect the resolved value
97+
/// - selected: Flag to know if chip is selected, by default is unselected
98+
/// - action: The action to perform when the user triggers the chip
99+
public init(icon: Image,
100+
_ key: LocalizedStringKey,
101+
tableName: String? = nil,
102+
bundle: Bundle = .main,
103+
comment: StaticString? = nil,
104+
selected: Bool = false,
105+
action: @escaping () -> Void)
106+
{
107+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
108+
if resolvedText.isEmpty {
109+
OL.warning("The OUDSFilterChip should not have an empty text, prefer instead OUDSFilterChip(icon:accessibilityLabel:selected:action).")
110+
}
111+
layout = .textAndIcon(text: resolvedText, icon: icon, iconPosition: .trailing)
112+
self.action = action
113+
self.selected = selected
114+
}
115+
85116
/// Create a chip with an icon only.
86117
///
87118
/// - Parameters:
@@ -113,6 +144,35 @@ public struct OUDSFilterChip: View {
113144
self.selected = selected
114145
}
115146

147+
/// Creates a filter chip with a localized text only, looking up the key in the given bundle.
148+
///
149+
/// ```swift
150+
/// OUDSFilterChip(LocalizedStringKey("category_filter"), bundle: Bundle.module, selected: false) { }
151+
/// ```
152+
///
153+
/// - Parameters:
154+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
155+
/// - tableName: The name of the `.strings` file, or `nil` for the default
156+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
157+
/// - comment: An optional comment for translators, does not affect the resolved value
158+
/// - selected: Flag to know if chip is selected, by default is unselected
159+
/// - action: The action to perform when the user triggers the chip
160+
public init(_ key: LocalizedStringKey,
161+
tableName: String? = nil,
162+
bundle: Bundle = .main,
163+
comment: StaticString? = nil,
164+
selected: Bool = false,
165+
action: @escaping () -> Void)
166+
{
167+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
168+
if resolvedText.isEmpty {
169+
OL.fatal("The OUDSFilterChip must not have an empty text!")
170+
}
171+
layout = .text(resolvedText)
172+
self.action = action
173+
self.selected = selected
174+
}
175+
116176
// MARK: Body
117177

118178
public var body: some View {

OUDS/Core/Components/Sources/Controls/Chip/OUDSSuggestionChip.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,34 @@ public struct OUDSSuggestionChip: View {
8989
self.action = action
9090
}
9191

92+
/// Creates a chip with a localized text and icon, looking up the key in the given bundle.
93+
///
94+
/// ```swift
95+
/// OUDSSuggestionChip(icon: Image("ic_heart"), LocalizedStringKey("like_chip"), bundle: Bundle.module) { }
96+
/// ```
97+
///
98+
/// - Parameters:
99+
/// - icon: An image which shoud contains an icon
100+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
101+
/// - tableName: The name of the `.strings` file, or `nil` for the default
102+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
103+
/// - comment: An optional comment for translators, does not affect the resolved value
104+
/// - action: The action to perform when the user triggers the chip
105+
public init(icon: Image,
106+
_ key: LocalizedStringKey,
107+
tableName: String? = nil,
108+
bundle: Bundle = .main,
109+
comment: StaticString? = nil,
110+
action: @escaping () -> Void)
111+
{
112+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
113+
if resolvedText.isEmpty {
114+
OL.warning("The OUDSSuggestionChip should not have an empty text! Prefer instead OUDSSuggestionChip(icon:accessibilityLabel:action).")
115+
}
116+
layout = .textAndIcon(text: resolvedText, icon: icon, iconPosition: .leading)
117+
self.action = action
118+
}
119+
92120
/// Creates a chip with an icon only.
93121
///
94122
/// - Parameters:
@@ -116,6 +144,32 @@ public struct OUDSSuggestionChip: View {
116144
self.action = action
117145
}
118146

147+
/// Creates a chip with a localized text only, looking up the key in the given bundle.
148+
///
149+
/// ```swift
150+
/// OUDSSuggestionChip(LocalizedStringKey("category_chip"), bundle: Bundle.module) { }
151+
/// ```
152+
///
153+
/// - Parameters:
154+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
155+
/// - tableName: The name of the `.strings` file, or `nil` for the default
156+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
157+
/// - comment: An optional comment for translators, does not affect the resolved value
158+
/// - action: The action to perform when the user triggers the chip
159+
public init(_ key: LocalizedStringKey,
160+
tableName: String? = nil,
161+
bundle: Bundle = .main,
162+
comment: StaticString? = nil,
163+
action: @escaping () -> Void)
164+
{
165+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
166+
if resolvedText.isEmpty {
167+
OL.fatal("The OUDSSuggestionChip must not have an empty text!")
168+
}
169+
layout = .text(resolvedText)
170+
self.action = action
171+
}
172+
119173
// MARK: Body
120174

121175
public var body: some View {

0 commit comments

Comments
 (0)