Pluralization and Stringsdict
Handle plural rules across languages.
The Plurals Problem
English has two forms — 1 item, 2 items — so developers often write "\(n) item" + (n == 1 ? "" : "s"). This breaks badly: Arabic has six plural categories, Russian three, Japanese one. Hardcoding plural logic is a localization bug waiting to happen.
// FRAGILE — only works for English
let n = 5
let bad = "\(n) item" + (n == 1 ? "" : "s")
print(bad)Plural Categories
Unicode defines plural categories: zero, one, two, few, many, other. Each language uses a subset. The system chooses the right category for a number based on locale rules — you never write the rules yourself.
// English uses: one, other
// Russian uses: one, few, many, other
// Japanese uses: other (only)
// You provide a variant string per category needed.All lessons in this course
- String Catalogs and Localized Strings
- Pluralization and Stringsdict
- Locale-Aware Formatting
- Right-to-Left and Layout Direction