The String Catalogs file have built-in support for pluralization.
Table of Contents
String Catalogs
Adding a String Catalog to your app is as simple as creating the file:
For a detailed guide on how to add the localizable
extension to String
, read this Localization article.
Handling Plurals
Handling plurals has never been easier, the String Catalog has built-in support:
Forget about the if/else
statements for good 🙌
Usage
Using it is as straight forward as using the in-line components:
@State private var itemCount = 0
Text("\(itemCount) Books") // 0 Books, 1 Book, 2 Books
Or, if you are using the String extensions from the previous localization article:
@State private var itemCount = 0
Text("books".localized(with: [itemCount])) // 0 Books, 1 Book, 2 Books
Related Articles
- New App - Localization
- AdaptableStack
- Components
- Improve Build Times
- Xcode Templates
- String Extensions
- ViewStateController
- ViewModifiers