OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2010-2014, International Business Machines Corporation and | 3 * Copyright (C) 2010-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 | 7 |
8 #include "unicode/utypes.h" | 8 #include "unicode/utypes.h" |
9 | 9 |
10 #if !UCONFIG_NO_FORMATTING | 10 #if !UCONFIG_NO_FORMATTING |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 LocaleDisplayNamesImpl::localeDisplayName(const char* localeId, | 681 LocaleDisplayNamesImpl::localeDisplayName(const char* localeId, |
682 UnicodeString& result) const { | 682 UnicodeString& result) const { |
683 return localeDisplayName(Locale(localeId), result); | 683 return localeDisplayName(Locale(localeId), result); |
684 } | 684 } |
685 | 685 |
686 // private | 686 // private |
687 UnicodeString& | 687 UnicodeString& |
688 LocaleDisplayNamesImpl::localeIdName(const char* localeId, | 688 LocaleDisplayNamesImpl::localeIdName(const char* localeId, |
689 UnicodeString& result) const { | 689 UnicodeString& result) const { |
690 if (nameLength == UDISPCTX_LENGTH_SHORT) { | 690 if (nameLength == UDISPCTX_LENGTH_SHORT) { |
691 langData.getNoFallback("LanguagesShort", localeId, result); | 691 langData.getNoFallback("Languages%short", localeId, result); |
692 if (!result.isBogus()) { | 692 if (!result.isBogus()) { |
693 return result; | 693 return result; |
694 } | 694 } |
695 } | 695 } |
696 return langData.getNoFallback("Languages", localeId, result); | 696 return langData.getNoFallback("Languages", localeId, result); |
697 } | 697 } |
698 | 698 |
699 UnicodeString& | 699 UnicodeString& |
700 LocaleDisplayNamesImpl::languageDisplayName(const char* lang, | 700 LocaleDisplayNamesImpl::languageDisplayName(const char* lang, |
701 UnicodeString& result) const { | 701 UnicodeString& result) const { |
702 if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) { | 702 if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) { |
703 return result = UnicodeString(lang, -1, US_INV); | 703 return result = UnicodeString(lang, -1, US_INV); |
704 } | 704 } |
705 if (nameLength == UDISPCTX_LENGTH_SHORT) { | 705 if (nameLength == UDISPCTX_LENGTH_SHORT) { |
706 langData.get("LanguagesShort", lang, result); | 706 langData.get("Languages%short", lang, result); |
707 if (!result.isBogus()) { | 707 if (!result.isBogus()) { |
708 return adjustForUsageAndContext(kCapContextUsageLanguage, result); | 708 return adjustForUsageAndContext(kCapContextUsageLanguage, result); |
709 } | 709 } |
710 } | 710 } |
711 langData.get("Languages", lang, result); | 711 langData.get("Languages", lang, result); |
712 return adjustForUsageAndContext(kCapContextUsageLanguage, result); | 712 return adjustForUsageAndContext(kCapContextUsageLanguage, result); |
713 } | 713 } |
714 | 714 |
715 UnicodeString& | 715 UnicodeString& |
716 LocaleDisplayNamesImpl::scriptDisplayName(const char* script, | 716 LocaleDisplayNamesImpl::scriptDisplayName(const char* script, |
(...skipping 11 matching lines...) Expand all Loading... |
728 UnicodeString& | 728 UnicodeString& |
729 LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode, | 729 LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode, |
730 UnicodeString& result) const { | 730 UnicodeString& result) const { |
731 return scriptDisplayName(uscript_getName(scriptCode), result); | 731 return scriptDisplayName(uscript_getName(scriptCode), result); |
732 } | 732 } |
733 | 733 |
734 UnicodeString& | 734 UnicodeString& |
735 LocaleDisplayNamesImpl::regionDisplayName(const char* region, | 735 LocaleDisplayNamesImpl::regionDisplayName(const char* region, |
736 UnicodeString& result) const { | 736 UnicodeString& result) const { |
737 if (nameLength == UDISPCTX_LENGTH_SHORT) { | 737 if (nameLength == UDISPCTX_LENGTH_SHORT) { |
738 regionData.get("CountriesShort", region, result); | 738 regionData.get("Countries%short", region, result); |
739 if (!result.isBogus()) { | 739 if (!result.isBogus()) { |
740 return adjustForUsageAndContext(kCapContextUsageTerritory, result); | 740 return adjustForUsageAndContext(kCapContextUsageTerritory, result); |
741 } | 741 } |
742 } | 742 } |
743 regionData.get("Countries", region, result); | 743 regionData.get("Countries", region, result); |
744 return adjustForUsageAndContext(kCapContextUsageTerritory, result); | 744 return adjustForUsageAndContext(kCapContextUsageTerritory, result); |
745 } | 745 } |
746 | 746 |
747 UnicodeString& | 747 UnicodeString& |
748 LocaleDisplayNamesImpl::variantDisplayName(const char* variant, | 748 LocaleDisplayNamesImpl::variantDisplayName(const char* variant, |
749 UnicodeString& result) const { | 749 UnicodeString& result) const { |
750 // don't have a resource for short variant names | 750 // don't have a resource for short variant names |
751 langData.get("Variants", variant, result); | 751 langData.get("Variants", variant, result); |
752 return adjustForUsageAndContext(kCapContextUsageVariant, result); | 752 return adjustForUsageAndContext(kCapContextUsageVariant, result); |
753 } | 753 } |
754 | 754 |
755 UnicodeString& | 755 UnicodeString& |
756 LocaleDisplayNamesImpl::keyDisplayName(const char* key, | 756 LocaleDisplayNamesImpl::keyDisplayName(const char* key, |
757 UnicodeString& result) const { | 757 UnicodeString& result) const { |
758 // don't have a resource for short key names | 758 // don't have a resource for short key names |
759 langData.get("Keys", key, result); | 759 langData.get("Keys", key, result); |
760 return adjustForUsageAndContext(kCapContextUsageKey, result); | 760 return adjustForUsageAndContext(kCapContextUsageKey, result); |
761 } | 761 } |
762 | 762 |
763 UnicodeString& | 763 UnicodeString& |
764 LocaleDisplayNamesImpl::keyValueDisplayName(const char* key, | 764 LocaleDisplayNamesImpl::keyValueDisplayName(const char* key, |
765 const char* value, | 765 const char* value, |
766 UnicodeString& result) const { | 766 UnicodeString& result) const { |
| 767 if (uprv_strcmp(key, "currency") == 0) { |
| 768 // ICU4C does not have ICU4J CurrencyDisplayInfo equivalent for now. |
| 769 UErrorCode sts = U_ZERO_ERROR; |
| 770 UnicodeString ustrValue(value, -1, US_INV); |
| 771 int32_t len; |
| 772 UBool isChoice = FALSE; |
| 773 const UChar *currencyName = ucurr_getName(ustrValue.getTerminatedBuffer(
), |
| 774 locale.getBaseName(), UCURR_LONG_NAME, &isChoice, &len, &sts); |
| 775 if (U_FAILURE(sts)) { |
| 776 // Return the value as is on failure |
| 777 result = ustrValue; |
| 778 return result; |
| 779 } |
| 780 result.setTo(currencyName, len); |
| 781 return adjustForUsageAndContext(kCapContextUsageKeyValue, result); |
| 782 } |
| 783 |
767 if (nameLength == UDISPCTX_LENGTH_SHORT) { | 784 if (nameLength == UDISPCTX_LENGTH_SHORT) { |
768 langData.get("Types%short", key, value, result); | 785 langData.get("Types%short", key, value, result); |
769 if (!result.isBogus()) { | 786 if (!result.isBogus()) { |
770 return adjustForUsageAndContext(kCapContextUsageKeyValue, result); | 787 return adjustForUsageAndContext(kCapContextUsageKeyValue, result); |
771 } | 788 } |
772 } | 789 } |
773 langData.get("Types", key, value, result); | 790 langData.get("Types", key, value, result); |
774 return adjustForUsageAndContext(kCapContextUsageKeyValue, result); | 791 return adjustForUsageAndContext(kCapContextUsageKeyValue, result); |
775 } | 792 } |
776 | 793 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 || maxResultSize < 0) { | 1003 || maxResultSize < 0) { |
987 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; | 1004 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; |
988 return 0; | 1005 return 0; |
989 } | 1006 } |
990 UnicodeString temp(result, 0, maxResultSize); | 1007 UnicodeString temp(result, 0, maxResultSize); |
991 ((const LocaleDisplayNames *)ldn)->keyValueDisplayName(key, value, temp); | 1008 ((const LocaleDisplayNames *)ldn)->keyValueDisplayName(key, value, temp); |
992 return temp.extract(result, maxResultSize, *pErrorCode); | 1009 return temp.extract(result, maxResultSize, *pErrorCode); |
993 } | 1010 } |
994 | 1011 |
995 #endif | 1012 #endif |
OLD | NEW |