0

Using MacOS, I'm finding that titles in the Shortcuts App aren't being presented dynamically.

The code below always shows the default value for this Action in the Shortcuts App eg. "Not Found Again".


@available(macOS 13.0, *)
struct EnterValueIntent: AppIntent {
    
    static let title: LocalizedStringResource = LocalizedStringResource("entervalue", defaultValue: "Not Found again", table: "AppIntentLocalizable.strings", locale: Locale.current)
        
    @MainActor
    func perform() async throws -> some IntentResult {
        return.result(
            value: "result")
    }
}

I have a key value pair in the strings table (AppIntentLocalizable.strings):

"entervalue" = "Enter Value";

I have this string table file localized to my current locale.

I have also tried using the main localization file in the App (Localizable.strings) with the same result (The app uses this string table for localization across the app).

The localization file(s) has the correct targets and has the right localization. I can read from this file using NSLocalizedString in the App.

I also tried a get {} against title - which in the Shortcuts app then shows the struct name against the Action. Doesn't even show the default.

The Shortcut App will present the default value but doesn't seem to be hitting the string table when providing a list of titles for Actions.

Please help.

unB
  • 119
  • 1
  • 2
  • Looks like I will need to go back to the old Intents framework rather than AppIntent given I can't seem to use Localization in the Shortcuts App with the public API. – unB Feb 26 '23 at 10:26

1 Answers1

0

I also experience the same problem. I am trying to read strings from my Localizable.strings file to create a localized AppIntent title on iOS

There is not a lot of documentation but I am assuming I am doing it correctly based on the docs from apple.

https://developer.apple.com/documentation/foundation/localizedstringresource/3988421-init?changes=_6

static var title: LocalizedStringResource = .init(
    "shortcut.watch.channel.title",
    table: "Localizable.strings",
    locale: .current,
    bundle: .main,
    comment: ""
)

The custom shortcut just end up with the Struct name in the shortcut app.

struct WatchTVChannelIntent: AppIntent {

static var title: LocalizedStringResource = .init(
    "shortcut.watch.channel.title",
    table: "Localizable.strings",
    locale: .current,
    bundle: .main
    comment: ""
)

static var openAppWhenRun: Bool = true

@MainActor
func perform() async throws -> some ProvidesDialog {
    try await executeIntentAction()
}
Daniel B
  • 1
  • 1