/*
*******************************************************************************
-* Copyright (C) 2010, International Business Machines Corporation and *
-* others. All Rights Reserved. *
+* Copyright (C) 2010-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
*******************************************************************************
*/
const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(),
tableKey, subTableKey, itemKey,
&len, &status);
- if (U_SUCCESS(status)) {
+ if (U_SUCCESS(status) && len > 0) {
return result.setTo(s, len);
}
return result.setTo(UnicodeString(itemKey, -1, US_INV));
////////////////////////////////////////////////////////////////////////////////////////////////////
+LocaleDisplayNames::~LocaleDisplayNames() {}
+
UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(LocaleDisplayNames)
////////////////////////////////////////////////////////////////////////////////////////////////////
ICUDataTable regionData;
UnicodeString sep;
MessageFormat *format;
+ MessageFormat *keyTypeFormat;
public:
// constructor
, langData(U_ICUDATA_LANG, locale)
, regionData(U_ICUDATA_REGION, locale)
, format(NULL)
+ , keyTypeFormat(NULL)
{
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
}
UErrorCode status = U_ZERO_ERROR;
format = new MessageFormat(pattern, status);
+
+ UnicodeString ktPattern;
+ langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
+ if (ktPattern.isBogus()) {
+ ktPattern = UnicodeString("{0}={1}", -1, US_INV);
+ }
+ keyTypeFormat = new MessageFormat(ktPattern, status);
}
LocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() {
delete format;
+ delete keyTypeFormat;
}
const Locale&
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
- appendWithSep(resultRemainder, keyDisplayName(key, temp))
- .append("=")
- .append(keyValueDisplayName(key, value, temp2));
+ keyDisplayName(key, temp);
+ keyValueDisplayName(key, value, temp2);
+ if (temp2 != UnicodeString(value, -1, US_INV)) {
+ appendWithSep(resultRemainder, temp2);
+ } else if (temp != UnicodeString(key, -1, US_INV)) {
+ UnicodeString temp3;
+ Formattable data[] = {
+ temp,
+ temp2
+ };
+ FieldPosition fpos;
+ status = U_ZERO_ERROR;
+ keyTypeFormat->format(data, 2, temp3, fpos, status);
+ appendWithSep(resultRemainder, temp3);
+ } else {
+ appendWithSep(resultRemainder, temp)
+ .append((UChar)0x3d /* = */)
+ .append(temp2);
+ }
}
delete e;
}