Home > Back-end >  Localize String passed to a view
Localize String passed to a view

Time:03-07

I'm trying to localize some text passed to a view, I have the following:

NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
    SettingsRowsView(systemName: "greetingcard", image: "", title: "Connections")
}

I want to localize "Connections"

I tried:

NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
    SettingsRowsView(systemName: "greetingcard", image: "", title: LocalizedStringKey("Connections"))
}

but says: Cannot convert value of type 'LocalizedStringKey' to expected argument type 'String'

What's the correct way of doing this without creating an extra variable?

Edit:

I found this looking around: String.localizedStringWithFormat(NSLocalizedString("Connections", comment: ""))

Is this the latest workaround or is there a simpler more SwiftUI version?

CodePudding user response:

Change SettingsRowsView to take a LocalizedStringKey for the title instead of taking a String.

  • Related