Return LocalizedStringResource from a method

I'm trying to localize an iOS App Intent, but my strings are in a different table/file ("AppIntents.strings"). For this reason I'd like to create a wrapper that automatically sets this table. However, this only seems to work when I directly set the LocalizedStringResource. If I create a method that returns it, it does not work. Using a static property also does not seem to work. In these two cases, it seems to fall back to the class name of my intent ("ExampleIntent").

Below is an example of what I've tried. Is there a way to make this work?

@available(iOS 16, *)
extension LocalizedStringResource {
    static func demo(_ key: String.LocalizationValue) -> LocalizedStringResource {
        LocalizedStringResource(key, table: "AppIntents")
    }

    static var demo2: LocalizedStringResource {
        LocalizedStringResource("localization.key", table: "AppIntents")
    }
}

@available(iOS 16, *)
struct ExampleIntent: AppIntent {
    // This works
    static var title: LocalizedStringResource = LocalizedStringResource("localization.key", table: "AppIntents")

    // This does not work
    // static var title: LocalizedStringResource = .demo("localization.key")

    // This does not work either
    // static var title: LocalizedStringResource = .demo2

    func perform() async throws -> some IntentResult {
        return .result()
    }
}

I have the exact same problem. Did you ever find a solution?

The only implementation that I found (for a swift package) that works like this is (using the new String Catalogs; untested with legacy string files)

let key:String.LocalizationValue = String.LocalizationValue(stringLiteral: "<localization key>")
return String(localized: key, table: "<String Catalog Table Name>", bundle: Bundle.module)

I have this implemented and working in one of my SPM projects, but you'll need to change Bundle.module to Bundle.main, or just leave it blank, for it to maybe work in an App (I haven't tested it).

Return LocalizedStringResource from a method
 
 
Q