< prev index next >

src/java.base/share/classes/java/util/Locale.java

Print this page
rev 49575 : imported patch 8181157


2172 
2173     private String getDisplayKeyTypeExtensionString(String key, LocaleResources lr, Locale inLocale) {
2174         String type = localeExtensions.getUnicodeLocaleType(key);
2175         String ret = getDisplayString(type, key, inLocale, DISPLAY_UEXT_TYPE);
2176 
2177         if (ret == null || ret.equals(type)) {
2178             // no localization for this type. try combining key/type separately
2179             String displayType = type;
2180             switch (key) {
2181             case "cu":
2182                 displayType = lr.getCurrencyName(type.toLowerCase(Locale.ROOT));
2183                 break;
2184             case "rg":
2185                 if (type != null &&
2186                     // UN M.49 code should not be allowed here
2187                     type.matches("^[a-zA-Z]{2}[zZ]{4}$")) {
2188                         displayType = lr.getLocaleName(type.substring(0, 2).toUpperCase(Locale.ROOT));
2189                 }
2190                 break;
2191             case "tz":
2192                 displayType = TimeZoneNameUtility.retrieveGenericDisplayName(
2193                     TimeZoneNameUtility.convertLDMLShortID(type).orElse(type),
2194                     TimeZone.LONG, inLocale);
2195                 break;
2196             }
2197             ret = MessageFormat.format(lr.getLocaleName("ListKeyTypePattern"),
2198                 getDisplayString(key, null, inLocale, DISPLAY_UEXT_KEY),
2199                 Optional.ofNullable(displayType).orElse(type));
2200         }
2201 
2202         return ret;
2203     }
2204 
2205     /**
2206      * Format a list using given pattern strings.
2207      * If either of the patterns is null, then a the list is
2208      * formatted by concatenation with the delimiter ','.
2209      * @param stringList the list of strings to be formatted.
2210      * and formatting them into a list.
2211      * @param pattern should take 2 arguments for reduction
2212      * @return a string representing the list.
2213      */
2214     private static String formatList(String[] stringList, String pattern) {




2172 
2173     private String getDisplayKeyTypeExtensionString(String key, LocaleResources lr, Locale inLocale) {
2174         String type = localeExtensions.getUnicodeLocaleType(key);
2175         String ret = getDisplayString(type, key, inLocale, DISPLAY_UEXT_TYPE);
2176 
2177         if (ret == null || ret.equals(type)) {
2178             // no localization for this type. try combining key/type separately
2179             String displayType = type;
2180             switch (key) {
2181             case "cu":
2182                 displayType = lr.getCurrencyName(type.toLowerCase(Locale.ROOT));
2183                 break;
2184             case "rg":
2185                 if (type != null &&
2186                     // UN M.49 code should not be allowed here
2187                     type.matches("^[a-zA-Z]{2}[zZ]{4}$")) {
2188                         displayType = lr.getLocaleName(type.substring(0, 2).toUpperCase(Locale.ROOT));
2189                 }
2190                 break;
2191             case "tz":
2192                 displayType = TimeZoneNameUtility.convertLDMLShortID(type)
2193                     .map(id -> TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.LONG, inLocale))
2194                     .orElse(type);
2195                 break;
2196             }
2197             ret = MessageFormat.format(lr.getLocaleName("ListKeyTypePattern"),
2198                 getDisplayString(key, null, inLocale, DISPLAY_UEXT_KEY),
2199                 Optional.ofNullable(displayType).orElse(type));
2200         }
2201 
2202         return ret;
2203     }
2204 
2205     /**
2206      * Format a list using given pattern strings.
2207      * If either of the patterns is null, then a the list is
2208      * formatted by concatenation with the delimiter ','.
2209      * @param stringList the list of strings to be formatted.
2210      * and formatting them into a list.
2211      * @param pattern should take 2 arguments for reduction
2212      * @return a string representing the list.
2213      */
2214     private static String formatList(String[] stringList, String pattern) {


< prev index next >