summaryrefslogtreecommitdiff
path: root/thirdparty/icu4c/common/locdspnm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/icu4c/common/locdspnm.cpp')
-rw-r--r--thirdparty/icu4c/common/locdspnm.cpp68
1 files changed, 47 insertions, 21 deletions
diff --git a/thirdparty/icu4c/common/locdspnm.cpp b/thirdparty/icu4c/common/locdspnm.cpp
index 43334f5196..f73cedd728 100644
--- a/thirdparty/icu4c/common/locdspnm.cpp
+++ b/thirdparty/icu4c/common/locdspnm.cpp
@@ -313,29 +313,29 @@ public:
LocaleDisplayNamesImpl(const Locale& locale, UDisplayContext *contexts, int32_t length);
virtual ~LocaleDisplayNamesImpl();
- virtual const Locale& getLocale() const;
- virtual UDialectHandling getDialectHandling() const;
- virtual UDisplayContext getContext(UDisplayContextType type) const;
+ virtual const Locale& getLocale() const override;
+ virtual UDialectHandling getDialectHandling() const override;
+ virtual UDisplayContext getContext(UDisplayContextType type) const override;
virtual UnicodeString& localeDisplayName(const Locale& locale,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& localeDisplayName(const char* localeId,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& languageDisplayName(const char* lang,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& scriptDisplayName(const char* script,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& regionDisplayName(const char* region,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& variantDisplayName(const char* variant,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& keyDisplayName(const char* key,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
virtual UnicodeString& keyValueDisplayName(const char* key,
const char* value,
- UnicodeString& result) const;
+ UnicodeString& result) const override;
private:
UnicodeString& localeIdName(const char* localeId,
UnicodeString& result, bool substitute) const;
@@ -407,7 +407,7 @@ struct LocaleDisplayNamesImpl::CapitalizationContextSink : public ResourceSink {
virtual ~CapitalizationContextSink();
virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
- UErrorCode &errorCode) {
+ UErrorCode &errorCode) override {
ResourceTable contexts = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
for (int i = 0; contexts.getKeyAndValue(i, key, value); ++i) {
@@ -723,11 +723,25 @@ LocaleDisplayNamesImpl::localeIdName(const char* localeId,
return result;
}
}
- if (substitute) {
- return langData.get("Languages", localeId, result);
- } else {
- return langData.getNoFallback("Languages", localeId, result);
+ langData.getNoFallback("Languages", localeId, result);
+ if (result.isBogus() && uprv_strchr(localeId, '_') == NULL) {
+ // Canonicalize lang and try again, ICU-20870
+ // (only for language codes without script or region)
+ Locale canonLocale = Locale::createCanonical(localeId);
+ const char* canonLocId = canonLocale.getName();
+ if (nameLength == UDISPCTX_LENGTH_SHORT) {
+ langData.getNoFallback("Languages%short", canonLocId, result);
+ if (!result.isBogus()) {
+ return result;
+ }
+ }
+ langData.getNoFallback("Languages", canonLocId, result);
}
+ if (result.isBogus() && substitute) {
+ // use key, this is what langData.get (with fallback) falls back to.
+ result.setTo(UnicodeString(localeId, -1, US_INV)); // use key (
+ }
+ return result;
}
UnicodeString&
@@ -742,10 +756,22 @@ LocaleDisplayNamesImpl::languageDisplayName(const char* lang,
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
}
}
- if (substitute == UDISPCTX_SUBSTITUTE) {
- langData.get("Languages", lang, result);
- } else {
- langData.getNoFallback("Languages", lang, result);
+ langData.getNoFallback("Languages", lang, result);
+ if (result.isBogus()) {
+ // Canonicalize lang and try again, ICU-20870
+ Locale canonLocale = Locale::createCanonical(lang);
+ const char* canonLocId = canonLocale.getName();
+ if (nameLength == UDISPCTX_LENGTH_SHORT) {
+ langData.getNoFallback("Languages%short", canonLocId, result);
+ if (!result.isBogus()) {
+ return adjustForUsageAndContext(kCapContextUsageLanguage, result);
+ }
+ }
+ langData.getNoFallback("Languages", canonLocId, result);
+ }
+ if (result.isBogus() && substitute == UDISPCTX_SUBSTITUTE) {
+ // use key, this is what langData.get (with fallback) falls back to.
+ result.setTo(UnicodeString(lang, -1, US_INV)); // use key (
}
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
}