swiftswiftuilocalizationios16appintents

How to localize title and description? (LocalizedStringResource)


I am working on my SwiftUI project and added some AppIntents for the Shortcuts app. Currently I am not able to localize the title and description. The title and the description are of type LocalizedStringResource (available from iOS16+).

I tried to localize the following code to German, but I don't know how to do it.

struct Add_Memory_Shortcut: AppIntent {
    // The name of the action in Shortcuts
    // TODO: Localization
    static var title : LocalizedStringResource = "Create Memory"
    
    // Description of the action in Shortcuts
    // Category name allows you to group actions - shown when tapping on an app in the Shortcuts library
    static var description: IntentDescription = IntentDescription("Create a new memory", categoryName: "Creating")
}

Any help or link is appreciated. Thanks :)


Solution

  • I tried everything, only one thing works, add your localization strings in

    Localizable.strings
    

    And if you want to localize string with paramter

    //Localizable.strings
            "hello_user%@" = "Hello %@";
    //Your AppIntents
            let welcomeMSG = LocalizedStringResource("hello_user\(userName)")