I am internationalizing my app and am looking for a solution to how to deal with plural forms. I ran across Mozilla\'s PluralForm project, which essentially abstracts away the i
Smartling (a Translation Management Platform) has released an open source library for managing plurals in iOS. After having dealt with numerous clients having iOS plurals problems and not finding a solution that would work how we and our clients wanted, we decided to build our own.
The library takes the keys for the plural strings and extends them to contain the plural form based on the CLDR plural rules. The library provides an alternative function to NSLocalizedString called SLPluralizedString to do the look up.
An English source file would look like:
"%d Items Processed##{one}" = "1 Item Processed";
"%d Items Processed##{other}" = "%d Items Processed";
And you would use the SLPluralizedString function to look up the string:
SLPluralizedString(@”%d Items Processed”, numItems, @”Number of items processed”);
A translated Russian file would have the appropriate number of keys/values for the language:
"%d Items Processed##{one}" = "%d элемент обработан";
"%d Items Processed##{few}" = "%d элемента обработано";
"%d Items Processed##{many}" = "%d элементов обработано";
"%d Items Processed##{other}" = "%d элемента обработано";
The actual code wouldn't need to change depending on the language. One function would work across all languages and return the appropriate translated string.
Feel free to share comments, improvements, etc.