]> granicus.if.org Git - icu/commitdiff
ICU-12156 J, for locale disp name trailing parts, use internal methods that don't...
authorPeter Edberg <pedberg@unicode.org>
Sun, 28 Feb 2016 20:14:07 +0000 (20:14 +0000)
committerPeter Edberg <pedberg@unicode.org>
Sun, 28 Feb 2016 20:14:07 +0000 (20:14 +0000)
X-SVN-Rev: 38424

icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java

index 4ab482ceeba5eb8a7ed9b71e850e9d5c300d203c..50cec65ca3741d7cd6bb576023cd0ee6e5f98fe1 100644 (file)
@@ -54,12 +54,12 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
      * Capitalization context usage types for locale display names
      */
     private enum CapitalizationContextUsage {
-        LANGUAGE, 
-        SCRIPT, 
+        LANGUAGE,
+        SCRIPT,
         TERRITORY,
-        VARIANT, 
-        KEY, 
-        KEYVALUE 
+        VARIANT,
+        KEY,
+        KEYVALUE
     }
     /**
      * Capitalization transforms. For each usage type, indicates whether to titlecase for
@@ -338,17 +338,17 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
         StringBuilder buf = new StringBuilder();
         if (hasScript) {
             // first element, don't need appendWithSep
-            buf.append(scriptDisplayNameInContext(script)
+            buf.append(scriptDisplayNameInContext(script, true)
                     .replace(formatOpenParen, formatReplaceOpenParen)
                     .replace(formatCloseParen, formatReplaceCloseParen));
         }
         if (hasCountry) {
-            appendWithSep(regionDisplayName(country)
+            appendWithSep(regionDisplayName(country, true)
                     .replace(formatOpenParen, formatReplaceOpenParen)
                     .replace(formatCloseParen, formatReplaceCloseParen), buf);
         }
         if (hasVariant) {
-            appendWithSep(variantDisplayName(variant)
+            appendWithSep(variantDisplayName(variant, true)
                     .replace(formatOpenParen, formatReplaceOpenParen)
                     .replace(formatCloseParen, formatReplaceCloseParen), buf);
         }
@@ -358,10 +358,10 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
             while (keys.hasNext()) {
                 String key = keys.next();
                 String value = locale.getKeywordValue(key);
-                String keyDisplayName = keyDisplayName(key)
+                String keyDisplayName = keyDisplayName(key, true)
                         .replace(formatOpenParen, formatReplaceOpenParen)
                         .replace(formatCloseParen, formatReplaceCloseParen);
-                String valueDisplayName = keyValueDisplayName(key, value)
+                String valueDisplayName = keyValueDisplayName(key, value, true)
                         .replace(formatOpenParen, formatReplaceOpenParen)
                         .replace(formatCloseParen, formatReplaceCloseParen);
                 if (!valueDisplayName.equals(value)) {
@@ -431,15 +431,20 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
         return adjustForUsageAndContext(CapitalizationContextUsage.SCRIPT, str);
     }
 
-    @Override
-    public String scriptDisplayNameInContext(String script) {
+    private String scriptDisplayNameInContext(String script, boolean skipAdjust) {
         if (nameLength == DisplayContext.LENGTH_SHORT) {
             String scriptName = langData.get("Scripts%short", script);
             if (!scriptName.equals(script)) {
-                return adjustForUsageAndContext(CapitalizationContextUsage.SCRIPT, scriptName);
+                return skipAdjust? scriptName: adjustForUsageAndContext(CapitalizationContextUsage.SCRIPT, scriptName);
             }
         }
-        return adjustForUsageAndContext(CapitalizationContextUsage.SCRIPT, langData.get("Scripts", script));
+        String scriptName = langData.get("Scripts", script);
+        return skipAdjust? scriptName: adjustForUsageAndContext(CapitalizationContextUsage.SCRIPT, scriptName);
+    }
+
+    @Override
+    public String scriptDisplayNameInContext(String script) {
+        return scriptDisplayNameInContext(script, false);
     }
 
     @Override
@@ -447,31 +452,45 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
         return scriptDisplayName(UScript.getShortName(scriptCode));
     }
 
-    @Override
-    public String regionDisplayName(String region) {
+    private String regionDisplayName(String region, boolean skipAdjust) {
         if (nameLength == DisplayContext.LENGTH_SHORT) {
             String regionName = regionData.get("Countries%short", region);
             if (!regionName.equals(region)) {
-                return adjustForUsageAndContext(CapitalizationContextUsage.TERRITORY, regionName);
+                return skipAdjust? regionName: adjustForUsageAndContext(CapitalizationContextUsage.TERRITORY, regionName);
             }
         }
-        return adjustForUsageAndContext(CapitalizationContextUsage.TERRITORY, regionData.get("Countries", region));
+        String regionName = regionData.get("Countries", region);
+        return skipAdjust? regionName: adjustForUsageAndContext(CapitalizationContextUsage.TERRITORY, regionName);
     }
 
     @Override
-    public String variantDisplayName(String variant) {
+    public String regionDisplayName(String region) {
+        return regionDisplayName(region, false);
+    }
+
+    private String variantDisplayName(String variant, boolean skipAdjust) {
         // don't have a resource for short variant names
-        return adjustForUsageAndContext(CapitalizationContextUsage.VARIANT, langData.get("Variants", variant));
+        String variantName = langData.get("Variants", variant);
+        return skipAdjust? variantName: adjustForUsageAndContext(CapitalizationContextUsage.VARIANT, variantName);
     }
 
     @Override
-    public String keyDisplayName(String key) {
+    public String variantDisplayName(String variant) {
+        return variantDisplayName(variant, false);
+    }
+
+    private String keyDisplayName(String key, boolean skipAdjust) {
         // don't have a resource for short key names
-        return adjustForUsageAndContext(CapitalizationContextUsage.KEY, langData.get("Keys", key));
+        String keyName = langData.get("Keys", key);
+        return skipAdjust? keyName: adjustForUsageAndContext(CapitalizationContextUsage.KEY, keyName);
     }
 
     @Override
-    public String keyValueDisplayName(String key, String value) {
+    public String keyDisplayName(String key) {
+        return keyDisplayName(key, false);
+    }
+
+    private String keyValueDisplayName(String key, String value, boolean skipAdjust) {
         String keyValueName = null;
 
         if (key.equals("currency")) {
@@ -491,7 +510,12 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
             }
         }
 
-        return adjustForUsageAndContext(CapitalizationContextUsage.KEYVALUE, keyValueName);
+        return skipAdjust? keyValueName: adjustForUsageAndContext(CapitalizationContextUsage.KEYVALUE, keyValueName);
+    }
+
+    @Override
+    public String keyValueDisplayName(String key, String value) {
+        return keyValueDisplayName(key, value, false);
     }
 
     @Override
@@ -547,7 +571,7 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
     }
 
     private UiListItem newRow(ULocale modified, DisplayContext capContext) {
-        ULocale minimized = ULocale.minimizeSubtags(modified, ULocale.Minimize.FAVOR_SCRIPT); 
+        ULocale minimized = ULocale.minimizeSubtags(modified, ULocale.Minimize.FAVOR_SCRIPT);
         String tempName = modified.getDisplayName(locale);
         boolean titlecase = capContext == DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU;
         String nameInDisplayLocale =  titlecase ? UCharacter.toTitleFirst(locale, tempName) : tempName;
@@ -640,7 +664,7 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
 
     private StringBuilder appendWithSep(String s, StringBuilder b) {
         if (b.length() == 0) {
-            b.append(s); 
+            b.append(s);
         } else {
             SimpleFormatterImpl.formatAndReplace(separatorFormat, b, null, b, s);
         }
index d3031f9422d9e772a6ae40b147a8c48af2e9a255..407d073db17641ebbe8579fc78b4b0ce36110849 100644 (file)
@@ -274,7 +274,7 @@ public class ULocaleTest extends TestFmwk {
         if (!JAVA7_OR_LATER && !Locale.getDefault().equals(noNONY)) {
             errln("FAIL: ULocale#setDefault failed to set Java Locale no_NO_NY /actual: " + Locale.getDefault());
         }
-        Locale.setDefault(backupDefault);        
+        Locale.setDefault(backupDefault);
 
         // We also want to map ICU locale nn to Java no_NO_NY
         ULocale.setDefault(new ULocale("nn"));
@@ -1056,6 +1056,10 @@ public class ULocaleTest extends TestFmwk {
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, DisplayContext.LENGTH_FULL,  "en",    "Engelsk" ),
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU,       DisplayContext.LENGTH_FULL,  "en",    "Engelsk" ),
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_STANDALONE,            DisplayContext.LENGTH_FULL,  "en",    "engelsk" ),
+                    new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_FULL,  "en@calendar=buddhist", "engelsk (buddhistisk kalender)" ),
+                    new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, DisplayContext.LENGTH_FULL,  "en@calendar=buddhist", "Engelsk (buddhistisk kalender)" ),
+                    new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU,       DisplayContext.LENGTH_FULL,  "en@calendar=buddhist", "Engelsk (buddhistisk kalender)" ),
+                    new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_STANDALONE,            DisplayContext.LENGTH_FULL,  "en@calendar=buddhist", "engelsk (buddhistisk kalender)" ),
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_FULL,  "en_GB", "engelsk (Storbritannien)" ),
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, DisplayContext.LENGTH_FULL,  "en_GB", "Engelsk (Storbritannien)" ),
                     new TestContextItem( "da", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU,       DisplayContext.LENGTH_FULL,  "en_GB", "Engelsk (Storbritannien)" ),
@@ -1084,6 +1088,10 @@ public class ULocaleTest extends TestFmwk {
                     new TestContextItem( "es", DisplayContext.DIALECT_NAMES,  DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, DisplayContext.LENGTH_FULL,  "en_GB", "Ingl\u00E9s brit\u00E1nico" ),
                     new TestContextItem( "es", DisplayContext.DIALECT_NAMES,  DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU,       DisplayContext.LENGTH_FULL,  "en_GB", "Ingl\u00E9s brit\u00E1nico" ),
                     new TestContextItem( "es", DisplayContext.DIALECT_NAMES,  DisplayContext.CAPITALIZATION_FOR_STANDALONE,            DisplayContext.LENGTH_FULL,  "en_GB", "Ingl\u00E9s brit\u00E1nico" ),
+                    new TestContextItem( "ru", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_FULL,  "uz_Latn", "\u0443\u0437\u0431\u0435\u043A\u0441\u043A\u0438\u0439 (\u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430)" ),
+                    new TestContextItem( "ru", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, DisplayContext.LENGTH_FULL,  "uz_Latn", "\u0423\u0437\u0431\u0435\u043A\u0441\u043A\u0438\u0439 (\u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430)" ),
+                    new TestContextItem( "ru", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU,       DisplayContext.LENGTH_FULL,  "uz_Latn", "\u0423\u0437\u0431\u0435\u043A\u0441\u043A\u0438\u0439 (\u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430)" ),
+                    new TestContextItem( "ru", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_STANDALONE,            DisplayContext.LENGTH_FULL,  "uz_Latn", "\u0423\u0437\u0431\u0435\u043A\u0441\u043A\u0438\u0439 (\u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430)" ),
                     new TestContextItem( "en", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_FULL,  "ur@numbers=latn",    "Urdu (Western Digits)" ),
                     new TestContextItem( "en", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_FULL,  "ur@numbers=arabext", "Urdu (Extended Arabic-Indic Digits)" ),
                     new TestContextItem( "en", DisplayContext.STANDARD_NAMES, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    DisplayContext.LENGTH_SHORT, "ur@numbers=arabext", "Urdu (X Arabic-Indic Digits)" ),
@@ -1104,7 +1112,7 @@ public class ULocaleTest extends TestFmwk {
                         errln("FAIL: displayLoc: " + item.displayLocale + ", dialectNam?: " + item.dialectHandling +
                                 ", capitalize: " + item.capitalization + ", nameLen: " + item.nameLength + ", locToName: " + item.localeToBeNamed +
                                 ", => expected result: " + item.result + ", got: " + result);
-                    } 
+                    }
                 }
             }
         }
@@ -1410,13 +1418,13 @@ public class ULocaleTest extends TestFmwk {
         /*1*/ { "en", "false" },
         /*2*/ { "en", "true" }, // fell back from en-zzz to en
         /*3*/ { null, "true" },
-        /*4*/ { "es", "false" }, 
+        /*4*/ { "es", "false" },
         /*5*/ { "de", "false" },
         /*6*/ { "zh_TW", "false" },
         /*7*/ { "zh", "true" },
     };
 
-    private static final String ACCEPT_LANGUAGE_HTTP[] = { 
+    private static final String ACCEPT_LANGUAGE_HTTP[] = {
         /*0*/ "mt-mt, ja;q=0.76, en-us;q=0.95, en;q=0.92, en-gb;q=0.89, fr;q=0.87, iu-ca;q=0.84, iu;q=0.82, ja-jp;q=0.79, mt;q=0.97, de-de;q=0.74, de;q=0.71, es;q=0.68, it-it;q=0.66, it;q=0.63, vi-vn;q=0.61, vi;q=0.58, nl-nl;q=0.55, nl;q=0.53, th-th-traditional;q=.01",
         /*1*/ "ja;q=0.5, en;q=0.8, tlh",
         /*2*/ "en-zzz, de-lx;q=0.8",
@@ -1465,7 +1473,7 @@ public class ULocaleTest extends TestFmwk {
     }
 
     private ULocale[] StringToULocaleArray(String acceptLanguageList){
-        //following code is copied from 
+        //following code is copied from
         //ULocale.acceptLanguage(String acceptLanguageList, ULocale[] availableLocales, boolean[] fallback)
         class ULocaleAcceptLanguageQ implements Comparable {
             private double q;
@@ -1541,7 +1549,7 @@ public class ULocaleTest extends TestFmwk {
             n = itemEnd; // get next item. (n++ will skip over delimiter)
         }
 
-        // 2. pull out the map 
+        // 2. pull out the map
         ULocale acceptList[] = (ULocale[])map.values().toArray(new ULocale[map.size()]);
         return acceptList;
     }
@@ -1606,32 +1614,32 @@ public class ULocaleTest extends TestFmwk {
         }
     }
 
-    public void TestMinimize() { 
-        String[][] data = { 
-                // source, favorRegion, favorScript 
-                {"zh-Hans-CN", "zh", "zh"}, 
-                {"zh-Hant-TW", "zh-TW", "zh-Hant"}, 
-                {"zh-Hant-SG", "zh-Hant-SG", "zh-Hant-SG"}, 
-                {"zh-Hans-SG", "zh-SG", "zh-SG"}, 
-                {"zh-Hant-HK", "zh-HK", "zh-HK"}, 
-                {"en_Latn_US", "en", "en"}, 
-                {"en_Cyrl-US", "en-Cyrl", "en-Cyrl"}, 
-                {"en_Cyrl-RU", "en-Cyrl-RU", "en-Cyrl-RU"}, 
-                {"en_Latn-RU", "en-RU", "en-RU"}, 
-                {"sr_Cyrl-US", "sr-US", "sr-US"}, 
-                {"sr_Cyrl-RU", "sr-Cyrl-RU", "sr-Cyrl-RU"}, 
-                {"sr_Latn-RU", "sr-RU", "sr-RU"}, 
-        }; 
-        for (String[] test : data) { 
-            ULocale source = new ULocale(test[0]); 
-            ULocale expectedFavorRegion = new ULocale(test[1]); 
-            ULocale expectedFavorScript = new ULocale(test[2]); 
-            assertEquals("favor region:\t" + Arrays.asList(test).toString(), expectedFavorRegion,  
-                    ULocale.minimizeSubtags(source, Minimize.FAVOR_REGION)); 
-            assertEquals("favor script:\t" + Arrays.asList(test).toString(), expectedFavorScript,  
-                    ULocale.minimizeSubtags(source, Minimize.FAVOR_SCRIPT)); 
-        } 
-    } 
+    public void TestMinimize() {
+        String[][] data = {
+                // source, favorRegion, favorScript
+                {"zh-Hans-CN", "zh", "zh"},
+                {"zh-Hant-TW", "zh-TW", "zh-Hant"},
+                {"zh-Hant-SG", "zh-Hant-SG", "zh-Hant-SG"},
+                {"zh-Hans-SG", "zh-SG", "zh-SG"},
+                {"zh-Hant-HK", "zh-HK", "zh-HK"},
+                {"en_Latn_US", "en", "en"},
+                {"en_Cyrl-US", "en-Cyrl", "en-Cyrl"},
+                {"en_Cyrl-RU", "en-Cyrl-RU", "en-Cyrl-RU"},
+                {"en_Latn-RU", "en-RU", "en-RU"},
+                {"sr_Cyrl-US", "sr-US", "sr-US"},
+                {"sr_Cyrl-RU", "sr-Cyrl-RU", "sr-Cyrl-RU"},
+                {"sr_Latn-RU", "sr-RU", "sr-RU"},
+        };
+        for (String[] test : data) {
+            ULocale source = new ULocale(test[0]);
+            ULocale expectedFavorRegion = new ULocale(test[1]);
+            ULocale expectedFavorScript = new ULocale(test[2]);
+            assertEquals("favor region:\t" + Arrays.asList(test).toString(), expectedFavorRegion,
+                    ULocale.minimizeSubtags(source, Minimize.FAVOR_REGION));
+            assertEquals("favor script:\t" + Arrays.asList(test).toString(), expectedFavorScript,
+                    ULocale.minimizeSubtags(source, Minimize.FAVOR_SCRIPT));
+        }
+    }
 
     public void TestAddLikelySubtags() {
         String[][] data = {
@@ -3879,7 +3887,7 @@ public class ULocaleTest extends TestFmwk {
         testCurrent = VersionInfo.getInstance(bundle.getString("CurrentCLDRVersion"));
 
 
-        logln("(data) ExpectCLDRVersionAtLeast { "+testExpect+""); 
+        logln("(data) ExpectCLDRVersionAtLeast { "+testExpect+"");
         if(cldrVersion.compareTo(testExpect)<0) {
             errln("CLDR version is too old, expect at least "+testExpect+".");
         }
@@ -4050,7 +4058,7 @@ public class ULocaleTest extends TestFmwk {
             new ULocale("en").getDisplayKeywordValue("calendar",ULocale.GERMAN);
         } catch (Exception e) {
             errln("Unexpected exception: " + e.getMessage());
-        }  
+        }
     }
 
     public void TestGetFallback() {
@@ -4073,7 +4081,7 @@ public class ULocaleTest extends TestFmwk {
         }
 
         // Testing ULocale getFallback()
-        final ULocale[][] TESTLOCALES = 
+        final ULocale[][] TESTLOCALES =
             {
                 {new ULocale("en_US"), new ULocale("en"), ULocale.ROOT, null},
                 {new ULocale("en__POSIX"), new ULocale("en"), ULocale.ROOT, null},
@@ -4116,7 +4124,7 @@ public class ULocaleTest extends TestFmwk {
                 String kstr = testcase[i/2 + 1];
                 String ext = loc.getExtension(Character.valueOf(kstr.charAt(0)));
                 if (ext == null || !ext.equals(testcase[i/2 + 2])) {
-                    errln("Incorrect extension value: key=" 
+                    errln("Incorrect extension value: key="
                             + kstr + ", returned=" + ext + ", expected=" + testcase[i/2 + 2]
                                     + ", locale=" + testcase[0]);
                 }
@@ -4168,7 +4176,7 @@ public class ULocaleTest extends TestFmwk {
             // Check attributes
             Set<String> attributes = loc.getUnicodeLocaleAttributes();
             if (attributes.size() != expectedAttributes.size()) {
-                errln("Incorrect number for Unicode locale attributes: returned=" 
+                errln("Incorrect number for Unicode locale attributes: returned="
                         + attributes.size() + ", expected=" + expectedAttributes.size()
                         + ", locale=" + testcase[0]);
             }
@@ -4180,7 +4188,7 @@ public class ULocaleTest extends TestFmwk {
             Set<String> keys = loc.getUnicodeLocaleKeys();
             Set<String> expectedKeys = expectedKeywords.keySet();
             if (keys.size() != expectedKeys.size()) {
-                errln("Incorrect number for Unicode locale keys: returned=" 
+                errln("Incorrect number for Unicode locale keys: returned="
                         + keys.size() + ", expected=" + expectedKeys.size()
                         + ", locale=" + testcase[0]);
             }
@@ -4190,7 +4198,7 @@ public class ULocaleTest extends TestFmwk {
                 String expType = expectedKeywords.get(expKey);
 
                 if (type == null || !expType.equals(type)) {
-                    errln("Incorrect Unicode locale type: key=" 
+                    errln("Incorrect Unicode locale type: key="
                             + expKey + ", returned=" + type + ", expected=" + expType
                             + ", locale=" + testcase[0]);
                 }