Member-only story
Localisation in Xcode 15
Utilise new String Catalogs to internationalize your Swift apps
I mostly post to Substack these days. Subscribe now to receive non-paywalled, ludicrously in-depth articles on iOS, Swift, and indie projects every 2 weeks.
String Catalogs are a neat new feature introduced in WWDC 2023.
.strings
files (and, to an even greater extent, .stringsdict
files) were one of the final bastions of Objective-C-era cruft in the Apple development environment.
But no more.
I’ve been upgrading Bev, my trusty, boozy side project, to iOS 17. Along the way, I’ve been implementing the teachings from WWDC23’s Discover String Catalogs.
Join me on the journey!
The Bad Old World™
Prior to Xcode 15, most of your strings will be defined in a .strings
file:
// Home screen
"home_screen_title"="Home";
"home_screen_button_add_friend"="Add friend";
"home_screen_button_settings"="Settings";
"home_screen_friends_list"="Your friends list";
You missed one semicolon?
Too bad, every string in your module is now broken, displaying home_screen_title
or home_screen_button_add_friend
in place of your actual copy.
.stringsdict
files are even tougher to grasp. Because different languages have different grammatical rules for handling pluralisation, we need a far more complex beast to define a single string, even to say something as simple as “3 friends”:
<dict>
<key>home_screen_friends_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@friends_count@</string>
<key>friends_count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>No friends</string>
<key>one</key>
<string>1 friend</string>
<key>other</key>
<string>%d friends</string>
</dict>
</dict>
</dict>