Post

Replies

Boosts

Views

Activity

Reply to New iOS String Initializer can't get correct localized String for specific locale
As of macOS 14 and iOS 17 String(localized:defaultValue:table:bundle:locale:comment:) still has no documentation and the original poster's assumption that specifying a locale would retrieve the string localized for the locale specified seems, to me at least, the most plausible assumption of how this API works. Additionally, I do have a use-case where being able to retrieve particular strings, including complicated interpolated ones with pluralization, for a locale other than the user's current one easily would be beneficial: I'm building a simple language learning app in which the user can switch the language being studied. The languages being studied are independent of the UI locale. Accordingly I keep the localized UI strings and the content strings in a separate tables. The UI is localized via SwiftUI and occasionally simple String(localized:) calls. I was hoping I could get at the language learning content with the String(localized:defaultValue:table:bundle:locale:comment:) initializer - but no. In the past I have implemented my own content localization in bigger apps that needed this kind of separation but this seems excessive here. Maybe the ship on this API has sailed. If not I would be willing to go into detail and file a bug.
Nov ’23