0Pricing
Swift Academy · Lesson

Pluralization and Stringsdict

Handle plural rules across languages.

Pluralization and Stringsdict is a free Swift Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Plural Variants in a String Catalog

In a String Catalog you mark a string as having plural variations. Xcode then lets you supply text for each category. At runtime the correct variant is chosen automatically based on the interpolated count and the user's locale.

// Catalog entry, key "message_count":
//   one:   "You have %lld message"
//   other: "You have %lld messages"
let count = 1
let text = String(localized: "You have \(count) messages")
print(text)

The Legacy .stringsdict

Before String Catalogs, plurals lived in a .stringsdict file — a property list mapping a key to a format string plus per-category variants. You still see these in older projects and they remain fully supported.

// Localizable.stringsdict (plist) structure:
// key: "items_count"
//   NSStringLocalizedFormatKey: "%#@items@"
//   items: NSStringPluralRuleType
//     one:   "%lld item"
//     other: "%lld items"

Anatomy of a stringsdict Entry

Each entry has a format key referencing one or more named variables wrapped in %#@name@. Each variable declares its rule type (NSStringPluralRuleType), the value-type specifier (%lld), and a string per plural category.

// The %#@items@ token expands to the chosen
// plural variant. %lld is the integer placeholder
// substituted inside each variant string.
let n = 3
print(String(localized: "\(n) items selected"))

Looking Up a Pluralized String

From code the call site looks identical to any localized string — you just interpolate the count. The plural selection happens inside the framework, so the same line of Swift works in every language.

func messagesLabel(_ count: Int) -> String {
    return String(localized: "You have \(count) messages")
}
print(messagesLabel(0))
print(messagesLabel(1))
print(messagesLabel(7))

Why 'one' Is Not Just 1

A common mistake is assuming the one category means exactly the number 1. In some languages it covers any number ending in 1 (like 21, 31), and zero may or may not be distinct. Always provide text per category and let the rules decide.

// Russian: 1, 21, 31 -> 'one'
//          2, 3, 4    -> 'few'
//          5..20, 0   -> 'many'
// Never assume one == 1.

Combining Plurals With Other Values

A format can have several variables — for example a count and a name. Each can pluralize independently. In a String Catalog you mark which interpolation varies; the rest stays constant across variants.

let files = 2
let folder = "Photos"
let text = String(
    localized: "\(files) files in \(folder)")
// 'files' drives the plural; 'folder' is substituted as-is
print(text)

Width and Device Variants

The same catalog mechanism supports device and width variations, letting you show a short label on a watch and a longer one on iPad, or abbreviate when space is tight. These work alongside plural variants.

// Catalog can vary by:
//   plural: one / other
//   device: iPhone / iPad / watch
//   width:  short / medium / long
let label = String(localized: "Notifications")
print(label)

Testing Pluralization

To verify your variants, run the app in each target language using Xcode's scheme localization override, or use the pseudolanguage and per-locale previews. Spot-check the boundary numbers: 0, 1, 2, 5, 11, 21, 100.

let samples = [0, 1, 2, 5, 11, 21, 100]
for n in samples {
    print(String(localized: "\(n) items"))
}

Best Practices

For correct plurals:

  • Never concatenate or hardcode s suffixes.
  • Provide every category the target languages need.
  • Drive the plural from the interpolated integer, not a precomputed string.
  • Prefer String Catalogs for new code; keep .stringsdict only for legacy targets.
func cartSummary(_ items: Int) -> String {
    String(localized: "Your cart has \(items) items",
           comment: "Cart count; pluralized")
}
print(cartSummary(1))

Quick Check

Recall how plural selection should be handled.

Recap

You learned locale-correct pluralization:

  • Unicode plural categories are zero, one, two, few, many, other; each language uses a subset.
  • String Catalogs let you add plural variants per key; legacy .stringsdict does the same via a plist.
  • Call sites stay simple — interpolate the count and the framework picks the variant.
  • Never hardcode plural logic; the one category is not just the number 1.

Frequently asked questions

Is the “Pluralization and Stringsdict” lesson free?

Yes — the full text of “Pluralization and Stringsdict” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Pluralization and Stringsdict”?

Handle plural rules across languages. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Pluralization and Stringsdict” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. String Catalogs and Localized Strings
  2. Pluralization and Stringsdict
  3. Locale-Aware Formatting
  4. Right-to-Left and Layout Direction
← Back to Swift Academy