Localization - Pluralizations

The easiest way to support plurals

The String Catalogs file have built-in support for pluralization.

Official Apple Docs

Table of Contents

String Catalogs

Adding a String Catalog to your app is as simple as creating the file:

string-catalog

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:

vary-by-plural

pluralization

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


Localization - Pluralizations | manu.show
Tags: ios
Share: X (Twitter) LinkedIn