Using stringsdict to manage plurals in AppIntents

Hi there,

I'm currently adding AppIntents to my iOS app, using TypeDisplayRepresentation to identify each entity. I'm following the example provided in the docs for the name and numericFormat strings, and I have an accompanying stringsdict file of the same format as the example.

This works perfectly in the name of the actions, equivalent to Find Books/All Books, but now within my app anywhere the key value is used (in this example, the string "Book"), %#@VARIABLE@ is literally substituted in. I think the issue is I'm not sure how to handle a NSStringLocalizedFormatKey which is just a single word.

Should I be defining the strings differently within my SwiftUI views to fix this, or is there a problem in my stringsdict file? Thank you!

Answered by Frameworks Engineer in 751591022

There's a couple things you could try, assuming you're currently defining the key in code as LocalizedStringResource("Book").

  1. Use a separate table for the App Intents strings i.e. LocalizedStringResource("Book", table: "AppShortcuts"). This will separate "Book" as defined in your AppShortcuts.strings / AppShortcuts.stringsdict table from the default Localizable.string / Localizable.stringsdict table that's used in the rest of your app.
  2. Use a more unique key identifier with default value in your code i.e. LocalizedStringResource("Book.variable", defaultValue: "Book")
Accepted Answer

There's a couple things you could try, assuming you're currently defining the key in code as LocalizedStringResource("Book").

  1. Use a separate table for the App Intents strings i.e. LocalizedStringResource("Book", table: "AppShortcuts"). This will separate "Book" as defined in your AppShortcuts.strings / AppShortcuts.stringsdict table from the default Localizable.string / Localizable.stringsdict table that's used in the rest of your app.
  2. Use a more unique key identifier with default value in your code i.e. LocalizedStringResource("Book.variable", defaultValue: "Book")

Thanks! A separate table has worked nicely.

Using stringsdict to manage plurals in AppIntents
 
 
Q