Re: Language tags
Re: Language tags
- Subject: Re: Language tags
- From: mmalcolm crawford <email@hidden>
- Date: Sun, 13 Apr 2003 20:48:13 -0700
On Friday, April 4, 2003, at 12:46 AM, Yuhui wrote:
I've figured out how to use NSUserDefaults to get the user's language.
But the iCalendar format uses the 2-letter ISO 639 format, e.g.
"English" = "en". Short of writing a lookup table, is there any Apple
built-in function/dictionary to convert a language into the 2-letter
version?
The only way I've found so far is to use IntlUtility, as in:
IntlUtility *intlUtility = [IntlUtility sharedIntlUtility];
NSString *language = @"German";
NSLog(@"isoLanguageForLanguage %@ %@", language,
[intlUtility isoLanguageForLanguage:language]);
returns:
isoLanguageForLanguage German de
Alternatively, there's a EnglishToISO.strings file in
/System/Library/PrivateFrameworks/IntlPreferences.framework/Resources/,
which actually contains a dictionary with two keys ("EnglishNames" and
"ISOLanguageNames") whose values are arrays of English and ISO names.
You can use these to "translate" from English to ISO:
NSBundle *intlBundle = [NSBundle
bundleWithIdentifier:@"com.apple.IntlPreferences"];
NSString *isoPath = [intlBundle pathForResource:@"EnglishToISO"
ofType:@"strings"];
NSDictionary *isoDict = [NSDictionary
dictionaryWithContentsOfFile:isoPath];
NSLog(@"isoDict %@", [isoDict description]);
int englishIndex = [[isoDict objectForKey:@"EnglishNames"]
indexOfObject:@"English"];
NSString *isoCode = [[isoDict objectForKey:@"ISOLanguageNames"]
objectAtIndex:englishIndex];
isoCode = "en"
For going the other way, there's:
NSString *englishFromISO = [intlBundle
localizedStringForKey:@"en_GB"
value:nil
table:@"Language"];
What's interesting about EnglishToISO.strings is that the first line is:
"// copied from CFBundle_Resources.c in CoreFoundation."
All of these are in a private framework. I'd love to hear of public
API for this stuff -- I'm sure I must have missed something obvious,
especially given the comment above.
Also of interest: the SACountry country class, from
/System/Library/PrivateFrameworks/International.framework/, which
includes methods like:
+ countryWithISOCode:
- appropriateLanguages
and
- isoCountryNumber
mmalc
_______________________________________________
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.