Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLocalizedString and plural form



On Oct 18, 2007, at 4:46 PM, Andrey Subbotin wrote:
Hello all,

I've been looking eagerly through the Internationalization
Programming Topics at Apple's site and am kind of puzzled. The
problem I try to solve is providing a Russian language localization
for my project and I'm unable to find a way to properly localize
plural forms.

Say, we have the following three cases:

- 1 file has just been copied.
- 2 files have just been copied.
- 5 files have just been copied.

That is, in the English language there're only 2 forms. If all the
languages followed this pattern, then the code to localize it could
look like this:

if (x == 1) {
  str = NSLocalizedString(@"%d file has just been copied.", nil);
} else {
  str = NSLocalizedString(@"%d files have just been copied.", nil);
}

Then... in Russian there'd be more plural forms. The above three
lines would be:

- 1 fail skopirovalsya.
- 2 faila skopirovalis'.
- 5 failov skopirovalos'.

The cases like this make it impossible to simply use the above two
NSLocalizedString keys to retrieve the proper translation.

The gettext library can handle these things well by providing a way
to specify the number of plural forms in its dictionary files
(Please see the following page where it all is described in greater
details: http://www.gnu.org/software/libc/manual/html_node/Advanced-
gettext-functions.html ). But even if I can use the gettext library
in Objective-C apps, gettext is no way Cocoa.

The question is: How do I properly localize plural forms using the
Cocoa APIs? Is it at all possible?

I'd gladly appreciate any hints, etc. Thanks in advance.

You could take the list of all languages you're supporting (let's assume for the sake of this e-mail as just English and Russian) and first localize for the language that needs the most unique terms (Russian in this case).

Your code would then need to work with that most specific case:

if (x == 1) str = NSLocalizedString("KEY_1",...);
else if (x == 2) str = NSLocalizedString("KEY_2",...);
else str = NSLocalizedString("KEY_3",...);

In your localized .strings for Russian, you'd then have:

"KEY_1" = "%d fail";
"KEY_2" = "%d faila";
"KEY_2" = "%d failov";

In your English .strings, you'd then have some redundancy:

"KEY_1" = "%d file"
"KEY_2" = "%d files";
"KEY_3" = "%d files";

I know that I would lean towards this approach if I ever localized my
product (which also currently has quite a bit of code like yours to
handle singular/plural cases).

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

I would be more than happy if Cocoa had something like Perl's "maketext" (which takes care of some of gettext's problems):


http://search.cpan.org/dist/Locale-Maketext/lib/Locale/Maketext/TPJ13.pod#A_Localization_Horror_Story :_It_Could_Happen_To_You

Does anyone know if there are such solutions available for Cocoa? I've been looking but havn't found something yet...

Thanks / Mattias
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.