XEEPluralizer is a class that helps you perform gramtically correct pluralization of the words in various languages. Pluralization is a trivial task for most of the well known world's langauges. But for some langages (mostly Slavic) it can be a nuisance.
For example, in English, the word "wolf" would be pluralized like this:
- 1 wolf
- 2 wolves
- 3 wolves
- ...
In Slovenian, for example, the same thing would look like this:
- 1 volk
- 2 volkovi
- 3 volkova
- 4 volkova
- 5 volkov
- 6 volkov
- 7 volkov
- ...
In Croatian and Serbian, on the other hand, it would look like this:
- 1 vuk
- 2 vuka
- 3 vuka
- 4 vuka
- 5 vukova
- 6 vukova
- ...
- 11 vukova
- 12 vukova
- ...
- 20 vukova
- 21 vuk
- 22 vuka
- 23 vuka
- 24 vuka
- 25 vukova
- ...
Most common grammatical numbers are Singular and Plural. In theory, beside these there are also Dual, Trial, Quadral, Paucal, ... Some of these exist only in theory and aren't used in any official language (Trial, Quadral). Some are very rare (Dual) and some are normal occurance in many languages (Paucal).
XEEPluralizer* pluralizerWolf = [[XEEPluralizer alloc] initWithWordForms:
@{kXEEPluralizerFormSingular : NSLocalizedString(@"wolfSingular", nil),
kXEEPluralizerFormDual : NSLocalizedString(@"wolfDual", nil),
kXEEPluralizerFormPaucal : NSLocalizedString(@"wolfPaucal", nil),
kXEEPluralizerFormPlural : NSLocalizedString(@"wolfPlural", nil)
}];
for (int i = 0; i< 100; i++) {
NSLog(@"%@", [pluralizerWolf pluralizedSyntagmForQuantity:N]);
}
Localizable.strings // English
"wolfSingular" = "wolf";
"wolfPlural" = "wolves";
Localizable.strings // Croatian
"wolfSingular" = "vuk";
"wolfPaucal" = "vuka";
"wolfPlural" = "vukova";
Localizable.strings // Slovenian
"wolfSingular" = "volk";
"wolfDual" = "volkova";
"wolfPaucal" = "volkovi";
"wolfPlural" = "volkov";
Follow XEETech on Twitter (XEE Tech).
Connect with us on LinkedIn (@XEE_Tech).
XEEPluralizer is available under the MIT license. See the LICENSE file for more info.