Re: Internationalization: How to bring the locale in line
Re: Internationalization: How to bring the locale in line
- Subject: Re: Internationalization: How to bring the locale in line
- From: Severin Kurpiers <email@hidden>
- Date: Thu, 4 Nov 2004 10:30:54 +0100
Hi Uli,
maybe you should try something like this (here as the main function of
a small Foundation Tool, just for testing):
int main (int argc, const char * argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults* standardUserDefaults = [NSUserDefaults
standardUserDefaults];
NSString* myKey = @"NSDecimalSeparator";
float floatValue = 123.4;
NSDictionary* myLocale = [NSDictionary
dictionaryWithObject:[standardUserDefaults stringForKey:myKey]
forKey:myKey];
NSString* myString = [[NSString alloc] initWithFormat:@"%.1f"
locale:myLocale, floatValue];
NSLog(myString);
[myString release];
[pool release];
return 0;
}
The benefit would be that you will in any case use the current user
setting, which can be customized. Like on my machine: My preferred
language is set to "English" but Measurement Units is set to "Metric"
and Numbers to "1.2345,6 €"
It's only an idea but I hope it helps.
Bye,
Severin Kurpiers
Verek Ltd.
On 4. Nov 2004 Uli Zappe wrote:
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.
_______________________________________________
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