ICU-8423 Use stand-alone form of script name if possible in getDisplayScript() APIs

X-SVN-Rev: 30621
This commit is contained in:
John Emmons 2011-09-06 20:28:21 +00:00
parent 50758756b5
commit 2abb6e6d3b
4 changed files with 79 additions and 7 deletions

View 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);
}

View 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

View 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.

View 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);