Episode #499

Localizing Pluralized Phrases

Series: Localizing Your App

13 minutes
Published on August 5, 2021

This video is only available to subscribers. Get access to this video and 584 others.

Pluralization rules vary by language, so it's not as easy as just adding an "s". To properly handle these cases, we need to use a Stringsdict file and format our string using a special syntax.

Links

How to use it

Add a stringsdict file with the same name as your localized strings file: Localizable.stringsdict.

Add your pluralized entries in here. I recommend to use a real key rather than the format string. Add each plural rule, for English you really only need "one" and "other", but other languages will need additional rules.

Make sure your Localizable.strings file has this key defined and is not translated.

/* NOTRANSLATE You have %d meals planned this week */
"meals_planned_count" = "meals_planned_count";

Usage:

String.localizedStringWithFormat(
    NSLocalizedString("meals_planned_count", 
        comment: "You have %d meals planned this week"),
    mealsThisWeek.count)

This episode uses Xcode 12.5.