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