Skip navigation.
 
mlRe: Localization and plural rules revisited
FROM : Ricky Sharp
DATE : Tue May 20 21:48:42 2008

On May 20, 2008, at 12:08 PM, Peter Edberg wrote:

> CLDR (Common Locale Data Repository) has some draft data on plural 
> forms for various languages. See
> <http://unicode.org/cldr/data/charts/supplemental/language_plural_rules.html

> > for specific rules
> and
> <http://unicode.org/draft/reports/tr35/

> tr35.html#Language_Plural_Rules> for background info.


These are by far the best references I've seen to date.  Thanks!  Very 
interesting that Ukrainian has a special rule for fractional values 
vs. integers.

Anyhow, what follows is a summary of what I've learned, and what 
approach I plan to take.  I'll also mention a few things regarding 
other replies to this thread.

First, the MessageFormat and ChoiceFormat classes from the ICU project 
just won't cut it.  Too limited to handle various languages.  There is 
a followup class named PluralFormat which does work, but the syntax is 
quite difficult.  And, what Horst Hoesel brought up, you don't want to 
cause difficulties for translators.

I'm going to modify my code to create a utility object that will build 
up appropriate keys based upon what locale the user is currently using 
for my app's interface.  Each time I add another language to the list 
of localizations, I'll add in an appropriate rule function.  The 
function simply takes the quantity (n) and spits out what category 
should be used.  Category is the term used by the unicode.org links 
above.


Anyhow, imagine a key which is typically the original English phrase. 
I currently have:

"Move 1 unit to the right." = "Move 1 unit to the right.";
"Move %d units to the right." = "Move %d units to the right.";

Change will be:

"PluralFormONE_Move %d unit(s) to the right." = "Move 1 unit to the 
right.";
"PluralFormOTHER_Move %d unit(s) to the right." = "Move %d units to 
the right.";

i.e. the base key is now common to all entries.  I then prefix 
"PluralForm" which gives translators something to search on. 
Following that prefix would be category as shown on the unicode.org 
link above.

Finally, calling code would be something like this:

NSLocalizedString ([MyUtility keyForPluralRuleWithBaseKey:@"Move %d 
unit(s) to the right."
    quantity:someValue],
    @"localization context comment goes here");

To keep things generic, the quantity param can be an NSNumber 
representing either an integer or fractional value.  Or, just overload 
the API; one with int, one with float/double.

___________________________________________________________
Ricky A. Sharp        mailto:<email_removed>
Instant Interactive(tm)  http://www.instantinteractive.com

Related mailsAuthorDate
mlLocalization and plural rules revisited Ricky Sharp May 20, 05:02
mlRe: Localization and plural rules revisited Horst Hoesel May 20, 11:54
mlRe: Localization and plural rules revisited RICKY SHARP May 20, 13:25
mlRe: Localization and plural rules revisited Horst Hoesel May 20, 14:21
mlRe: Localization and plural rules revisited Stephen F. Booth May 20, 17:09
mlRe: Localization and plural rules revisited Peter Edberg May 20, 19:08
mlRe: Localization and plural rules revisited Ricky Sharp May 20, 21:48
mlRe: Localization and plural rules revisited Peter Edberg May 20, 22:27
mlRe: Localization and plural rules revisited Gary L. Wade May 20, 22:40
mlRe: Localization and plural rules revisited Ricky Sharp May 21, 00:04
mlRe: Localization and plural rules revisited Ricky Sharp May 21, 00:06
mlRe: Localization and plural rules revisited Gerriet M. Denkman… May 21, 00:20
mlRe: Localization and plural rules revisited Ricky Sharp May 21, 00:30
mlRe: Localization and plural rules revisited Lachlan Deck May 21, 02:54