Re: objectForKey crashes for string formats
Re: objectForKey crashes for string formats
- Subject: Re: objectForKey crashes for string formats
- From: Chris Hanson <email@hidden>
- Date: Thu, 22 May 2003 09:21:46 -0400
On Thursday, May 22, 2003, at 03:35 AM, Lorenzo wrote:
I use a NSDictionary to localize my software in different languages.
Why not use Cocoa's built-in support for localization? It's much
cleaner, and requires virtually no work on your part while developing
your software.
For instance, you would write
errorFormat = NSLocalizedString(@"The file \"%1$@\" cannot be saved."
@"Can't save file. (filename)");
and then the appropriate message would be picked up from the current
language's Localizable.strings file, if one exists. If one doesn't,
the message itself will be passed through. The second string is a
comment; when you run genstrings on your code to generate an initial
Localizable.strings file from your NSLocalizedString declarations, this
comment is added to the file.
The "1$" above indicates which argument should be substituted. For
instance, English writes given and then family name, but Japanese
writes family and then given name. You could write
nameFormat = NSLocalizedString(@"My name is %1$@ %2$@.",
@"full name (given, family)");
and then in your Japanese.lproj/Localizable.strings, have
/* full name (given, family) */
"My name is %1$@ %2$@." = "My name is %2$@ %1$@."
and the Right Thing would happen when you wrote
myName = [NSString stringWithFormat:nameFormat, givenName,
familyName];
Cool, huh?
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.