mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
d14deaae2c
commit
4faf3c4eda
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>
|
2010-10-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/ObjectiveC2/GNUmakefile:
|
* Source/ObjectiveC2/GNUmakefile:
|
||||||
|
|
|
@ -479,14 +479,64 @@ static NSArray *_currencyCodesWithType (uint32_t currType)
|
||||||
- (NSString *) displayNameForKey: (id) key value: (id) value
|
- (NSString *) displayNameForKey: (id) key value: (id) value
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
int32_t length;
|
int32_t length = 0;
|
||||||
unichar buffer[ULOC_FULLNAME_CAPACITY];
|
unichar buffer[ULOC_FULLNAME_CAPACITY];
|
||||||
UErrorCode status;
|
UErrorCode status;
|
||||||
|
const char *keyword = NULL;
|
||||||
const char *locale = [[self localeIdentifier] cString];
|
const char *locale = [[self localeIdentifier] cString];
|
||||||
|
|
||||||
length = uloc_getDisplayKeywordValue (locale, [key cString],
|
if ([key isEqualToString: NSLocaleIdentifier])
|
||||||
[value cString], (UChar *)buffer, sizeof(buffer)/sizeof(unichar),
|
{
|
||||||
&status);
|
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))
|
if (U_FAILURE(status))
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue