mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Fix -displayNameForKey:value: to interact properly with libicu for some
common cases. More arcane locale components still need proper treatment. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31566 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d01fbf4669
commit
057dd3f2f1
2 changed files with 59 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
2010-10-26 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Source/NSLocale.m: Fix -displayNameForKey:value: to interact properly
|
||||
with libicu for some common cases.
|
||||
|
||||
2010-10-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/ObjectiveC2/GNUmakefile:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue