From: John Emmons Date: Tue, 6 Sep 2011 20:28:21 +0000 (+0000) Subject: ICU-8423 Use stand-alone form of script name if possible in getDisplayScript() APIs X-Git-Tag: milestone-59-0-1~4551 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2abb6e6d3bc74ddb12066b47a87028a314340e02;p=icu ICU-8423 Use stand-alone form of script name if possible in getDisplayScript() APIs X-SVN-Rev: 30621 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java index 0ee5cb65024..35da507d28d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java @@ -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); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/LocaleDisplayNames.java b/icu4j/main/classes/core/src/com/ibm/icu/text/LocaleDisplayNames.java index 61c80892e82..becff45938e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/LocaleDisplayNames.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/LocaleDisplayNames.java @@ -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 diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java index da95103639e..7f8016eaefc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java @@ -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 DISPLAY 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 DISPLAY locale. * @return the localized country name. diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index 726e8e8d036..76f6521f732 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -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);