Re: Internationalization: How to bring the locale in line with the language?
Re: Internationalization: How to bring the locale in line with the language?
- Subject: Re: Internationalization: How to bring the locale in line with the language?
- From: Uli Zappe <email@hidden>
- Date: Thu, 4 Nov 2004 02:59:55 +0100
Am 03.11.2004 um 20:52 schrieb Jonathon Mah:
On 4 Nov 2004, at 02:15, Uli Zappe wrote:
No, but there I would have a hard time finding out what the used
language will be. I don't want to hardcode the locale (then I could
obviously simply not use localized methods in my app), but bring it
in line with the language the app actually uses depending on the
user's preferences and the available localized NIB files.
You could put each locale in the localized .strings file, and then set
the setting to whatever NSLocalizedString() returns. That way, it'd be
in English if it were using English strings, etc.
(I'm assuming that the application is set-up enough to use
NSLocalizedString() before NSApplicationMain() is called — I haven't
tried that yet.)
Yep, I ended up with a similar solution; however, if I use the
Localizable.strings files, there is no need for early initialization
anymore.
Here's the solution I came up with (only the decimal separator was
important to me):
In the Localizable.strings files of my supported languages I added an
entry
"NSDecimalSeparator" = ".";
(or "," dependant on the language).
Then, in my initialization code I set an instance variable:
myLocale=[[NSDictionary
dictionaryWithObject:NSLocalizedString(@"NSDecimalSeparator", @"")
forKey:@"NSDecimalSeparator"] retain];
From then on, I can generate correctly formatted strings dealing with
numeric values:
myString=[[[NSString alloc] initWithFormat:@"%.1f" locale:myLocale,
floatValue] autorelease];
In the text field formatters of my localized NIB files I use the
",<–>." option instead of the "Localize" option.
This works. I just feel it could be more straightforward.
Bye
Uli
________________________________________________________
Uli Zappe, Solmsstraße 5, D-65189 Wiesbaden, Germany
http://www.ritual.org
Fon: +49-700-ULIZAPPE
Fax: +49-700-ZAPPEFAX
________________________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden