Adri
Adri

Reputation: 111

SwiftUI AppIntents iOS16: How to localize Summary?

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
        }
    }

Upvotes: 11

Views: 1061

Answers (3)

antons
antons

Reputation: 178

You can specify the ParameterSummary strings filename like this:

static var parameterSummary: some ParameterSummary {
    Summary("add \(\.$numberOne) \(\.$numberTwo)", table: "AppShortcuts") {
        \.$numberThree
        \.$numberFour
    }
}

Upvotes: 1

zouritre
zouritre

Reputation: 655

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

Upvotes: 1

FPP
FPP

Reputation: 348

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.

Upvotes: 0

Related Questions