lukeredpath / swift-responsive-textfield

A SwiftUI wrapper around UITextField with binding-based state and responder control
Apache License 2.0
85 stars 15 forks source link

Add Support LocalizedString For Placeholder Text #16

Closed mergesort closed 1 year ago

mergesort commented 1 year ago

The current ResponsiveTextField initializer supports a placeholder property, but I can't find a way to pair it with a LocalizedString.

public init(
    placeholder: String,
    text: Binding<String>,
    isSecure: Bool = false,
    adjustsFontForContentSizeCategory: Bool = true,
    firstResponderDemand: Binding<FirstResponderDemand?>? = nil,
    configuration: Configuration = .empty,
    onFirstResponderStateChanged: FirstResponderStateChangeHandler? = nil,
    handleReturn: (() -> Void)? = nil,
    handleDelete: ((String) -> Void)? = nil,
    shouldChange: ((String, String) -> Bool)? = nil,
    supportedStandardEditActions: Set<StandardEditAction>? = nil,
    standardEditActionHandler: StandardEditActionHandling<UITextField>? = nil
) {
    self.placeholder = placeholder
    self.text = text
    self.firstResponderDemand = firstResponderDemand
    self.isSecure = isSecure
    self.configuration = configuration
    self.adjustsFontForContentSizeCategory = adjustsFontForContentSizeCategory
    self.onFirstResponderStateChanged = onFirstResponderStateChanged
    self.handleReturn = handleReturn
    self.handleDelete = handleDelete
    self.shouldChange = shouldChange
    self.supportedStandardEditActions = supportedStandardEditActions
    self.standardEditActionHandler = standardEditActionHandler
}

This is preventing me from using localized text like "ICON_SELECTION_VIEW_SEARCH_BAR_PLACEHOLDER_TEXT" = "Find an icon";. I tried going through the configuration property as well, is there any way to use localized strings with the placeholder property that I'm overlooking?

lukeredpath commented 1 year ago

The placeholder property is a String so I'm not sure what would be an appropriate API to expose here.

Have you tried using NSLocalizedString(...)?

mergesort commented 1 year ago

Oh duh, I've been working with SwiftUI so long that I completely forgot about NSLocalizedString as a viable option. Sorry about that, everything works great now!