]> granicus.if.org Git - icu/commitdiff
ICU-8423 Use stand-alone form of script name if possible in getDisplayScript() APIs
authorJohn Emmons <emmo@us.ibm.com>
Tue, 6 Sep 2011 20:28:21 +0000 (20:28 +0000)
committerJohn Emmons <emmo@us.ibm.com>
Tue, 6 Sep 2011 20:28:21 +0000 (20:28 +0000)
X-SVN-Rev: 30621

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

index 0ee5cb650248ad58587cce00e604f9850c86f7c9..35da507d28d10779f2f8b3a09d06667d78fd340a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2009-2010, International Business Machines Corporation and    *
+ * Copyright (C) 2009-2011, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -144,7 +144,7 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
         StringBuilder buf = new StringBuilder();
         if (hasScript) {
             // first element, don't need appender
-            buf.append(scriptDisplayName(script));
+            buf.append(scriptDisplayNameInContext(script));
         }
         if (hasCountry) {
             appender.append(regionDisplayName(country), buf);
@@ -191,6 +191,16 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
 
     @Override
     public String scriptDisplayName(String script) {
+        String str = langData.get("Scripts%stand-alone", script);
+        if ( str.equals(script) ) {
+            return langData.get("Scripts", script);
+        } else {
+            return str;
+        }
+    }
+
+    @Override
+    public String scriptDisplayNameInContext(String script) {
         return langData.get("Scripts", script);
     }
 
index 61c80892e82420021ac1bd3e43b06bac2a9ccc20..becff45938eea6242ca201a8d9cb1c5a2e6d67d3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2009-2010, International Business Machines Corporation and    *
+ * Copyright (C) 2009-2011, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -118,6 +118,18 @@ public abstract class LocaleDisplayNames {
      * @stable ICU 4.4
      */
     public abstract String scriptDisplayName(String script);
+    /**
+     * Returns the display name of the provided script code
+     * when used in the context of a full locale name.
+     * @param script the script code
+     * @return the display name of the provided script code
+     * @internal ICU 49
+     * @deprecated This API is ICU internal only.
+     */
+    public String scriptDisplayNameInContext(String script) {
+        return scriptDisplayName(script);
+    }
 
     /**
      * Returns the display name of the provided script code.  See
index da95103639ea9810c1830d43c7db13fdd2b3ed21..7f8016eaefc141d0a2aab2991049248d3048ce81 100644 (file)
@@ -1297,6 +1297,17 @@ public final class ULocale implements Serializable {
         return getDisplayScriptInternal(this, getDefault(Category.DISPLAY));
     }
 
+    /**
+     * {@icu} Returns this locale's script localized for display in the default <code>DISPLAY</code> locale.
+     * @return the localized script name.
+     * @see Category#DISPLAY
+     * @internal ICU 49
+     * @deprecated This API is ICU internal only.
+     */
+    public String getDisplayScriptInContext() {
+        return getDisplayScriptInContextInternal(this, getDefault(Category.DISPLAY));
+    }
+
     /**
      * {@icu} Returns this locale's script localized for display in the provided locale.
      * @param displayLocale the locale in which to display the name.
@@ -1307,6 +1318,17 @@ public final class ULocale implements Serializable {
         return getDisplayScriptInternal(this, displayLocale);
     }
 
+    /**
+     * {@icu} Returns this locale's script localized for display in the provided locale.
+     * @param displayLocale the locale in which to display the name.
+     * @return the localized script name.
+     * @internal ICU 49
+     * @deprecated This API is ICU internal only.
+     */
+    public String getDisplayScriptInContext(ULocale displayLocale) {
+        return getDisplayScriptInContextInternal(this, displayLocale);
+    }
+
     /**
      * {@icu} Returns a locale's script localized for display in the provided locale.
      * This is a cover for the ICU4C API.
@@ -1318,6 +1340,18 @@ public final class ULocale implements Serializable {
     public static String getDisplayScript(String localeID, String displayLocaleID) {
         return getDisplayScriptInternal(new ULocale(localeID), new ULocale(displayLocaleID));
     }
+    /**
+     * {@icu} Returns a locale's script localized for display in the provided locale.
+     * This is a cover for the ICU4C API.
+     * @param localeID the id of the locale whose script will be displayed
+     * @param displayLocaleID the id of the locale in which to display the name.
+     * @return the localized script name.
+     * @internal ICU 49
+     * @deprecated This API is ICU internal only.
+     */
+    public static String getDisplayScriptInContext(String localeID, String displayLocaleID) {
+        return getDisplayScriptInContextInternal(new ULocale(localeID), new ULocale(displayLocaleID));
+    }
 
     /**
      * {@icu} Returns a locale's script localized for display in the provided locale.
@@ -1329,6 +1363,17 @@ public final class ULocale implements Serializable {
     public static String getDisplayScript(String localeID, ULocale displayLocale) {
         return getDisplayScriptInternal(new ULocale(localeID), displayLocale);
     }
+    /**
+     * {@icu} Returns a locale's script localized for display in the provided locale.
+     * @param localeID the id of the locale whose script will be displayed.
+     * @param displayLocale the locale in which to display the name.
+     * @return the localized script name.
+     * @internal ICU 49
+     * @deprecated This API is ICU internal only.
+     */
+    public static String getDisplayScriptInContext(String localeID, ULocale displayLocale) {
+        return getDisplayScriptInContextInternal(new ULocale(localeID), displayLocale);
+    }
 
     // displayLocaleID is canonical, localeID need not be since parsing will fix this.
     private static String getDisplayScriptInternal(ULocale locale, ULocale displayLocale) {
@@ -1336,6 +1381,11 @@ public final class ULocale implements Serializable {
             .scriptDisplayName(locale.getScript());
     }
 
+    private static String getDisplayScriptInContextInternal(ULocale locale, ULocale displayLocale) {
+        return LocaleDisplayNames.getInstance(displayLocale)
+            .scriptDisplayNameInContext(locale.getScript());
+    }
+
     /**
      * Returns this locale's country localized for display in the default <code>DISPLAY</code> locale.
      * @return the localized country name.
index 726e8e8d036e023932438faaaa809e86a8c9d05c..76f6521f7324ae0cee68c639d0949d7b3afc9778 100644 (file)
@@ -991,7 +991,7 @@ public class ULocaleTest extends TestFmwk {
                       ", " + l.getDisplayName(ULocale.FRANCE));
 
                 String language = l.getDisplayLanguage();
-                String script = l.getDisplayScript();
+                String script = l.getDisplayScriptInContext();
                 String country = l.getDisplayCountry();
                 String variant = l.getDisplayVariant();
 
@@ -1002,7 +1002,7 @@ public class ULocaleTest extends TestFmwk {
 
                     name = l.getDisplayName(dl);
                     language = l.getDisplayLanguage(dl);
-                    script = l.getDisplayScript(dl);
+                    script = l.getDisplayScriptInContext(dl);
                     country = l.getDisplayCountry(dl);
                     variant = l.getDisplayVariant(dl);
 
@@ -1075,7 +1075,7 @@ public class ULocaleTest extends TestFmwk {
                 logln("Testing "+ testLocale+".....");
                 name = ULocale.getDisplayName(localeID, testLocale);
                 language = ULocale.getDisplayLanguage(localeID, testLocale);
-                script = ULocale.getDisplayScript(localeID, testLocale);
+                script = ULocale.getDisplayScriptInContext(localeID, testLocale);
                 country = ULocale.getDisplayCountry(localeID, testLocale);
                 variant = ULocale.getDisplayVariant(localeID, testLocale);
 
@@ -1092,7 +1092,7 @@ public class ULocaleTest extends TestFmwk {
                 logln("Testing "+ testLocale+".....");
                 name = ULocale.getDisplayName(localeID, loc);
                 language = ULocale.getDisplayLanguage(localeID, loc);
-                script = ULocale.getDisplayScript(localeID, loc);
+                script = ULocale.getDisplayScriptInContext(localeID, loc);
                 country = ULocale.getDisplayCountry(localeID, loc);
                 variant = ULocale.getDisplayVariant(localeID, loc);