SwiftUI AppIntents iOS16: How to localize Summary?
Asked Answered
Z

3

8

Im trying to localize the Summary of my new SwiftUI AppIntent on my Swift project for making new Shortcuts.

I am not able to localize the Summary. I have created a AppShortcuts.strings with Localize of English and Spanish languages like in this page appears: click here.

AppShortcuts.string (es):

"add ${numberOne} ${numberTwo}" = "Sumar: ${numberOne} ${numberTwo}";

Shortcut:

static var parameterSummary: some ParameterSummary {
        Summary("add \(\.$numberOne) \(\.$numberTwo)") {
            \.$numberThree
            \.$numberFour
        }
    }
Zanezaneski answered 6/10, 2022 at 9:3 Comment(0)
I
0

As stated in the article you have already mentioned these directives have to go into Localizable.strings:

ParameterSummary – This one is tricky. You'd think that because it has a variable it should be with the translations of the phrases in AppShortcuts.strings, but no, it belongs in Localizable.strings.

Don't know why but that works for me.

Iolite answered 22/12, 2022 at 16:18 Comment(0)
A
0

Create your translation in Localizable.strings this way:

"Do something with ${text}" = "Do something with ${text}";

You have to put the exact name of the parameter you are interpolating, if you do interpolate.

static var parameterSummary: some ParameterSummary {
    Summary("Do something \(\.$text)")
}

@Parameter(title: "To do")
var text: String
Adulterate answered 14/8, 2023 at 20:32 Comment(0)
S
0

You can specify the ParameterSummary strings filename like this:

static var parameterSummary: some ParameterSummary {
    Summary("add \(\.$numberOne) \(\.$numberTwo)", table: "AppShortcuts") {
        \.$numberThree
        \.$numberFour
    }
}
Stringpiece answered 11/12, 2023 at 18:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.