Plurals localization using Stringsdict in iOS

🌍 🌏 🌎

What it is about?

If you’re interested in the title, then you’re probably as concerned as I am about the localization issue of your iOS (macOS) application. A solid approach to the localization process of your application is a simple and effective way to increase the volume of your target audience. Often it makes no sense to put language barrier between the app and your target audience.

Problem 1. Noun plurals

Describing plurals of noun with variable amount is not a trivial task. Moreover, as we will convince later, it’s not a software engineer task from the beginning.

//a == 0 -> John has 0 pineapple
//a == 1 -> John has 1 pineapple
//a == 4 -> John has 4 pineapple

Example 1. Simple solution (wrong one)

Lets try to solve the task of building text string describing amount of pineapples owned by John in our source code using programming language only.

a == 0 -> John has no pineapples
a == 1 -> John has 1 pineapple
a == 4 -> John has 4 pineapples

Problem 2. Noun plurals localization

Inevitable localization task of our pineapple counting application is approaching. Here starts the real challenge.

Stringsdict using Plural Rule

Unlike simple Localizable.strings file, Localizable.strigsdict file is a structure much more sophisticated, and so much more functional. It is applicable not only to replace the incoming string with its localized equivalent, but also is able to take into account the formatting parameters included in the string and build the result in accordance with the selected rule for each one of the parameter.

Example 2. Applying Stringsdict

Now we are about to solve out text string building task without any noun amount counting inside of source code, but only with the power of Stringsdict and Plural Rule inside of it.

count==0, resultString=="John has no pineapples"
count==1, resultString=="John has 1 pineapple"
count==2, resultString=="John has 2 pineapples"


Now what about localization task?

Click “+” and choose “Russian”
Choose “Localizable.stringsdict”
Exporting files for localization
Choose a folder so save XLIFF file(s)
Choose “Editor” and click “Import Localizations…”
Locate localized ru.xliff file
Check the changes and press “Import”
Localizable.stringsdict (Russian) final look

Final test

Now our project is capable of building target “johns pineapples count” strings independently of count parameter and prefered system localization (if Localizable.stringsdict is available).

English localization example
Russian localization example


In the case when your project faces a task of building text string with the inclusion of sets of nouns with variable number and their subsequent localization, the sequence of your actions will be approximately as follows:

  1. Create Localizable.stringsdict file and define your string constant in accordance with Plural Rule.
  2. Enable target language localization for Localizable.stringsdict.
  3. Export Localizable.stringsdict into XLIFF file for target localization.
  4. Provide XLIFF file to localization specialist for processing.
  5. Export post-localized XLIFF file back into your project.
  6. Test your project.

iOS (Objective-C, Swift) and Android (Java) software engineer