Re: Localization and plural rules revisited
Re: Localization and plural rules revisited
- Subject: Re: Localization and plural rules revisited
- From: "Stephen F. Booth" <email@hidden>
- Date: Tue, 20 May 2008 08:09:28 -0700
I would recommend using ICU (http://icu-project.org) for more advanced
localization options. In particular have a look at the MessageFormat
and ChoiceFormat classes.
For example, here is an ICU code snippet for formatting a string
representing the number of files on a disk:
UErrorCode success = U_ZERO_ERROR;
MessageFormat* form("The disk \"{1}\" contains {0}.", success);
double filelimits[] = {0,1,2};
UnicodeString filepart[] = {"no files","one file","{0,number} files"};
ChoiceFormat* fileform = new ChoiceFormat(filelimits, filepart, 3);
form.setFormat(1, *fileform); // NOT zero, see below
Formattable testArgs[] = {1273L, "MyDisk"};
UnicodeString string;
FieldPosition fpos = 0;
cout << form.format(testArgs, 2, string, fpos, success) << endl;
// output, with different testArgs
// output: The disk "MyDisk" contains no files.
// output: The disk "MyDisk" contains one file.
// output: The disk "MyDisk" contains 1,273 files.
(from http://icu-project.org/apiref/icu4c/classMessageFormat.html)
Stephen
_______________________________________________
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:
This email sent to email@hidden