diff --git a/ChangeLog b/ChangeLog index d2ed60fad..a1b9897a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-26 Niels Grewe + + * Source/NSLocale.m: Fix -displayNameForKey:value: to interact properly + with libicu for some common cases. + 2010-10-22 Richard Frith-Macdonald * Source/ObjectiveC2/GNUmakefile: diff --git a/Source/NSLocale.m b/Source/NSLocale.m index 571f449d1..b3564393a 100644 --- a/Source/NSLocale.m +++ b/Source/NSLocale.m @@ -479,14 +479,64 @@ static NSArray *_currencyCodesWithType (uint32_t currType) - (NSString *) displayNameForKey: (id) key value: (id) value { #if GS_USE_ICU == 1 - int32_t length; + int32_t length = 0; unichar buffer[ULOC_FULLNAME_CAPACITY]; UErrorCode status; + const char *keyword = NULL; const char *locale = [[self localeIdentifier] cString]; - length = uloc_getDisplayKeywordValue (locale, [key cString], - [value cString], (UChar *)buffer, sizeof(buffer)/sizeof(unichar), - &status); + if ([key isEqualToString: NSLocaleIdentifier]) + { + length = uloc_getDisplayName([value UTF8String], locale, + (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } + else if ([key isEqualToString: NSLocaleLanguageCode]) + { + length = uloc_getDisplayLanguage([value UTF8String], locale, + (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } + else if ([key isEqualToString: NSLocaleCountryCode]) + { + length = uloc_getDisplayCountry([value UTF8String], locale, + (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } + else if ([key isEqualToString: NSLocaleScriptCode]) + { + length = uloc_getDisplayCountry([value UTF8String], locale, + (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } + else if ([key isEqualToString: NSLocaleVariantCode]) + { + length = uloc_getDisplayVariant([value UTF8String], locale, + (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } + else if ([key isEqualToString: NSLocaleCalendar]) + { + keyword = ICUCalendarKeyword; + } + else if ([key isEqualToString: NSLocaleCollationIdentifier]) + { + keyword = ICUCollationKeyword; + } + else + { + return nil; + } + + /* + * TODO: Implement handling of the other locale component constants. + */ + if (NULL != keyword) + { + length = uloc_getDisplayKeywordValue ([value UTF8String], keyword, + locale, (UChar *)buffer, sizeof(buffer)/sizeof(unichar), + &status); + } if (U_FAILURE(status)) return nil;