ICU-3440 ulocale, some display name work remaining
X-SVN-Rev: 15192
This commit is contained in:
parent
d26294f47f
commit
9f8f3ace99
@ -11,7 +11,6 @@ import java.io.Serializable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Enumeration; // get rid of this
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -911,8 +910,8 @@ public final class ULocale implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an enumeration of keywords for the specified locale.
|
* Gets an iterator over keywords for the specified locale.
|
||||||
* @return enumeration of keywords or null if there are no keywords.
|
* @return iterator over keywords
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public Iterator getKeywords() {
|
public Iterator getKeywords() {
|
||||||
@ -1527,7 +1526,7 @@ public final class ULocale implements Serializable {
|
|||||||
* present.
|
* present.
|
||||||
*/
|
*/
|
||||||
public String getKeywordValue(String keywordName) {
|
public String getKeywordValue(String keywordName) {
|
||||||
return (String)getKeywordMap().get(keywordName);
|
return (String)getKeywordMap().get(keywordName.trim().toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1638,10 +1637,29 @@ public final class ULocale implements Serializable {
|
|||||||
return EMPTY_STRING;
|
return EMPTY_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display names
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a name for the locale's language that is appropriate for display to the
|
* Utility to fetch locale display data from resource bundle tables.
|
||||||
* user's defalt locale.
|
*/
|
||||||
* @return String the display string
|
private static String getTableString(String tableName, String subtableName, String item, ULocale displayLocale) {
|
||||||
|
try {
|
||||||
|
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(displayLocale);
|
||||||
|
ICUResourceBundle table = bundle.get(tableName);
|
||||||
|
if (subtableName != null) {
|
||||||
|
table = bundle.get(subtableName);
|
||||||
|
}
|
||||||
|
return table.getString(item);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this locale's language localized for display in the default locale.
|
||||||
|
* @return the localized language name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayLanguage() {
|
public String getDisplayLanguage() {
|
||||||
@ -1649,44 +1667,52 @@ public final class ULocale implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the language name suitable for display for the specified locale.
|
* Return this locale's language localized for display in the provided locale.
|
||||||
*
|
* @param displayLocale the locale in which to display the name.
|
||||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
* @return the localized language name.
|
||||||
* if the locale's language code is "en", passing Locale::getFrench() for
|
|
||||||
* inLocale would result in "Anglais", while passing Locale::getGerman()
|
|
||||||
* for inLocale would result in "Englisch".
|
|
||||||
* @return String the displayable language string.
|
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayLanguage(ULocale displayLocale) {
|
public String getDisplayLanguage(ULocale displayLocale) {
|
||||||
return getDisplayLanguage(localeID, displayLocale.localeID);
|
return getDisplayLanguage(localeID, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a name for the locale's language that is appropriate for display to the
|
* Return a locale's language localized for display in the provided locale.
|
||||||
* user's defalt locale. This is a cover for the ICU4C API.
|
* This is a cover for the ICU4C API.
|
||||||
* @param localeID
|
* @param localeID the id of the locale whose language will be displayed
|
||||||
* @param displayLocaleID
|
* @param displayLocaleID the id of the locale in which to display the name.
|
||||||
* @return String the display string
|
* @return the localized language name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayLanguage(String localeID, String displaylocaleID) {
|
public static String getDisplayLanguage(String localeID, String displayLocaleID) {
|
||||||
// TODO: get resource information
|
return getDisplayLanguage(localeID, new ULocale(displayLocaleID));
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a locale's language localized for display in the provided locale.
|
||||||
|
* This is a cover for the ICU4C API.
|
||||||
|
* @param localeID the id of the locale whose language will be displayed.
|
||||||
|
* @param displayLocale the locale in which to display the name.
|
||||||
|
* @return the localized language name.
|
||||||
|
* @draft ICU 3.0
|
||||||
|
*/
|
||||||
|
public static String getDisplayLanguage(String localeID, ULocale displayLocale) {
|
||||||
|
return getTableString("Languages", null, new IDParser(localeID).getLanguage(), displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the script name suitable for display for the user's default locale.
|
* Return this locale's script localized for display in the default locale.
|
||||||
* @return String the displayable script string.
|
* @return the localized script name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayScript() {
|
public String getDisplayScript() {
|
||||||
return getDisplayScript(getDefault());
|
return getDisplayScript(getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the script name suitable for display for the specified locale.
|
* Return this locale's script localized for display in the provided locale.
|
||||||
* @param displayLocale the locale to get the displayable script code with. Null may be used to specify the default.
|
* @param displayLocale the locale in which to display the name.
|
||||||
* @return String the displayable script string.
|
* @return the localized script name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayScript(ULocale displayLocale) {
|
public String getDisplayScript(ULocale displayLocale) {
|
||||||
@ -1694,181 +1720,201 @@ public final class ULocale implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the script name suitable for display for the specified locale.
|
* Return a locale's script localized for display in the provided locale.
|
||||||
* @param localeID
|
* This is a cover for the ICU4C API.
|
||||||
* @param displayLocale the locale to get the displayable script code with. Null may be used to specify the default.
|
* @param localeID the id of the locale whose script will be displayed
|
||||||
* @return String the displayable script string.
|
* @param displayLocaleID the id of the locale in which to display the name.
|
||||||
|
* @return the localized script name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayScript(String localeID, String displaylocaleID) {
|
public static String getDisplayScript(String localeID, String displayLocaleID) {
|
||||||
// TODO: get resource information
|
return getDisplayScript(localeID, new ULocale(displayLocaleID));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the country name suitable for display for the user's default locale.
|
* Return a locale's script localized for display in the provided locale.
|
||||||
* @return String the displayable country string.
|
* @param localeID the id of the locale whose script will be displayed.
|
||||||
* @draft ICU 3.0
|
* @param displayLocale the locale in which to display the name.
|
||||||
|
* @return the localized script name.
|
||||||
|
* @draft ICU 3.0
|
||||||
|
*/
|
||||||
|
public static String getDisplayScript(String localeID, ULocale displayLocale) {
|
||||||
|
return getTableString("Scripts", null, new IDParser(localeID).getScript(), displayLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this locale's country localized for display in the default locale.
|
||||||
|
* @return the localized country name.
|
||||||
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayCountry() {
|
public String getDisplayCountry() {
|
||||||
return getDisplayCountry(getDefault());
|
return getDisplayCountry(getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the country name suitable for display for the specified locale.
|
* Return this locale's country localized for display in the provided locale.
|
||||||
* @param displayLocale the locale to get the displayable country code with. Null may be used to specify the default.
|
* @param displayLocale the locale in which to display the name.
|
||||||
* @return String the displayable country string.
|
* @return the localized country name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayCountry(ULocale displayLocale){
|
public String getDisplayCountry(ULocale displayLocale){
|
||||||
return getDisplayCountry(localeID, displayLocale.localeID);
|
return getDisplayCountry(localeID, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the country name suitable for display for the user's default locale.
|
* Return a locale's country localized for display in the provided locale.
|
||||||
* @return String the displayable country string.
|
* This is a cover for the ICU4C API.
|
||||||
* @draft ICU 3.0
|
* @param localeID the id of the locale whose country will be displayed
|
||||||
|
* @param displayLocaleID the id of the locale in which to display the name.
|
||||||
|
* @return the localized country name.
|
||||||
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayCountry(String localeID, String displaylocaleID) {
|
public static String getDisplayCountry(String localeID, String displayLocaleID) {
|
||||||
// TODO: get resource information
|
return getDisplayCountry(localeID, new ULocale(displayLocaleID));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the variant name suitable for display for the specified locale.
|
* Return a locale's country localized for display in the provided locale.
|
||||||
* @return String the displayable variant string.
|
* This is a cover for the ICU4C API.
|
||||||
|
* @param localeID the id of the locale whose country will be displayed.
|
||||||
|
* @param displayLocale the locale in which to display the name.
|
||||||
|
* @return the localized country name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayVariant(){
|
public static String getDisplayCountry(String localeID, ULocale displayLocale) {
|
||||||
|
return getTableString("Countries", null, new IDParser(localeID).getCountry(), displayLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this locale's variant localized for display in the default locale.
|
||||||
|
* @return the localized variant name.
|
||||||
|
* @draft ICU 3.0
|
||||||
|
*/
|
||||||
|
public String getDisplayVariant() {
|
||||||
return getDisplayVariant(getDefault());
|
return getDisplayVariant(getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the variant name suitable for display for the specified locale.
|
* Return this locale's variant localized for display in the provided locale.
|
||||||
* @param displayLocale the locale to get the displayable variant code with. Null may be used to specify the default.
|
* @param displayLocale the locale in which to display the name.
|
||||||
* @return String the displayable variant string.
|
* @return the localized variant name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayVariant(ULocale displayLocale){
|
public String getDisplayVariant(ULocale displayLocale){
|
||||||
return getDisplayVariant(localeID, displayLocale.localeID);
|
return getDisplayVariant(localeID, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the variant name suitable for display for the specified locale.
|
* Return a locale's variant localized for display in the provided locale.
|
||||||
* @return String the displayable variant string.
|
* This is a cover for the ICU4C API.
|
||||||
|
* @param localeID the id of the locale whose variant will be displayed
|
||||||
|
* @param displayLocaleID the id of the locale in which to display the name.
|
||||||
|
* @return the localized variant name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayVariant(String localeID, String displaylocaleID){
|
public static String getDisplayVariant(String localeID, String displayLocaleID){
|
||||||
// TODO: get resource information
|
return getDisplayVariant(localeID, new ULocale(displayLocaleID));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the keyword name suitable for display for the user's default locale.
|
* Return a locale's variant localized for display in the provided locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* This is a cover for the ICU4C API.
|
||||||
* string for the keyword collation.
|
* @param localeID the id of the locale whose variant will be displayed.
|
||||||
* Usage:
|
* @param displayLocale the locale in which to display the name.
|
||||||
* <code>
|
* @return the localized variant name.
|
||||||
* TODO
|
* @draft ICU 3.0
|
||||||
* </code>
|
*/
|
||||||
* @param keyword The keyword whose display string needs to be returned.
|
public static String getDisplayVariant(String localeID, ULocale displayLocale) {
|
||||||
* @return String the display keyword string.
|
return getTableString("Variants", null, new IDParser(localeID).getVariant(), displayLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a keyword localized for display in the default locale.
|
||||||
|
* @param keyword the keyword to be displayed.
|
||||||
|
* @return the localized keyword name.
|
||||||
* @see #getKeywords
|
* @see #getKeywords
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayKeyword(String keyword){
|
public static String getDisplayKeyword(String keyword) {
|
||||||
return getDisplayKeyword(keyword, getDefault());
|
return getDisplayKeyword(keyword, getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the keyword name suitable for display for the specified locale.
|
* Return a keyword localized for display in the specified locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* @param keyword the keyword to be displayed.
|
||||||
* string for the keyword collation.
|
* @param displayLocaleID the id of the locale in which to display the keyword.
|
||||||
* Usage:
|
* @return the localized keyword name.
|
||||||
* <code>
|
|
||||||
* TODO
|
|
||||||
* </code>
|
|
||||||
* @param keyword The keyword whose display string needs to be returned.
|
|
||||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
|
||||||
* if the locale's language code is "en", passing Locale::getFrench() for
|
|
||||||
* inLocale would result in "Anglais", while passing Locale::getGerman()
|
|
||||||
* for inLocale would result in "Englisch". NULL may be used to specify the default.
|
|
||||||
* @return String the display keyword string.
|
|
||||||
* @see #getKeywords
|
* @see #getKeywords
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayKeyword(String keyword, ULocale displayLocale){
|
public static String getDisplayKeyword(String keyword, String displayLocaleID) {
|
||||||
return getDisplayKeyword(keyword, displayLocale.localeID);
|
return getDisplayKeyword(keyword, new ULocale(displayLocaleID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the keyword name suitable for display for the user's default locale.
|
* Return a keyword localized for display in the specified locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* @param keyword the keyword to be displayed.
|
||||||
* string for the keyword collation.
|
* @param displayLocale the locale in which to display the keyword.
|
||||||
* Usage:
|
* @return the localized keyword name.
|
||||||
* <code>
|
|
||||||
* TODO
|
|
||||||
* </code>
|
|
||||||
* @param keyword The keyword whose display string needs to be returned.
|
|
||||||
* @return String the display keyword string.
|
|
||||||
* @see #getKeywords
|
* @see #getKeywords
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayKeyword(String keyword, String displayLocaleID){
|
public static String getDisplayKeyword(String keyword, ULocale displayLocale) {
|
||||||
// TODO: get resource information
|
return getTableString("Keys", null, keyword.trim().toLowerCase(), displayLocale);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the keyword suitable for display for the user's default locale.
|
* Return a keyword value localized for display in the default locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* @param keyword the keyword whose value is to be displayed.
|
||||||
* string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
|
* @return the localized value name.
|
||||||
*
|
|
||||||
* @param keyword The keyword for whose value should be used.
|
|
||||||
* @return String the displayable keyword value.
|
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayKeywordValue(String keyword){
|
public String getDisplayKeywordValue(String keyword) {
|
||||||
return getDisplayKeywordValue(keyword, getDefault());
|
return getDisplayKeywordValue(keyword, getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the keyword suitable for display for the specified locale.
|
* Return a keyword value localized for display in the specified locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* @param keyword the keyword whose value is to be displayed.
|
||||||
* string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
|
* @param displayLocale the locale in which to display the value.
|
||||||
*
|
* @return the localized value name.
|
||||||
* @param keyword The keyword for whose value should be used.
|
|
||||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
|
||||||
* if the locale's language code is "en", passing Locale::getFrench() for
|
|
||||||
* inLocale would result in "Anglais", while passing Locale::getGerman()
|
|
||||||
* for inLocale would result in "Englisch". NULL may be used to specify the default.
|
|
||||||
* @return String the displayable keyword value.
|
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayKeywordValue(String keyword, ULocale displayLocale){
|
public String getDisplayKeywordValue(String keyword, ULocale displayLocale) {
|
||||||
return getDisplayKeywordValue(localeID, keyword, displayLocale.localeID);
|
return getDisplayKeywordValue(localeID, keyword, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the keyword suitable for display for the specified locale.
|
* Return a keyword value localized for display in the specified locale.
|
||||||
* E.g: for the locale string de_DE@collation=PHONEBOOK, this API gets the display
|
* @param localeID the id of the locale whose keyword value is to be displayed.
|
||||||
* string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
|
* @param keyword the keyword whose value is to be displayed.
|
||||||
*
|
* @param displayLocaleID the id of the locale in which to display the value.
|
||||||
* @param keyword The keyword whose value should be used.
|
* @return the localized value name.
|
||||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
|
||||||
* if the locale's language code is "en", passing Locale::getFrench() for
|
|
||||||
* inLocale would result in "Anglais", while passing Locale::getGerman()
|
|
||||||
* for inLocale would result in "Englisch". NULL may be used to specify the default.
|
|
||||||
* @return String the displayable keyword value.
|
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayKeywordValue(String localeID, String keyword, String displaylocaleID){
|
public String getDisplayKeywordValue(String localeID, String keyword, String displayLocaleID) {
|
||||||
// TODO: get resource information
|
return getDisplayKeywordValue(localeID, keyword, new ULocale(displayLocaleID));
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a keyword value localized for display in the specified locale.
|
||||||
|
* @param localeID the id of the locale whose keyword value is to be displayed.
|
||||||
|
* @param keyword the keyword whose value is to be displayed.
|
||||||
|
* @param displayLocaleID the id of the locale in which to display the value.
|
||||||
|
* @return the localized value name.
|
||||||
|
* @draft ICU 3.0
|
||||||
|
*/
|
||||||
|
public static String getDisplayKeywordValue(String localeID, String keyword, ULocale displayLocale) {
|
||||||
|
// TODO: funky currency fallback
|
||||||
|
|
||||||
|
keyword = keyword.trim().toLowerCase();
|
||||||
|
String value = new IDParser(localeID).getKeywordValue(keyword);
|
||||||
|
return getTableString("Types", keyword, value, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the full name suitable for display for the user's default locale.
|
* Return this locale name localized for display in the default locale.
|
||||||
* @return the displayable name for this locale
|
* @return the localized locale name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
@ -1876,27 +1922,89 @@ public final class ULocale implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the full name suitable for display for the specified locale.
|
* Return this locale name localized for display in the provided locale.
|
||||||
*
|
* @param displayLocale the locale in which to display the locale name.
|
||||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
* @return the localized locale name.
|
||||||
* if the locale's language code is "en", passing ULocale(Locale::getFrench()) for
|
|
||||||
* inLocale would result in "Anglais", while passing ULocale(Locale::getGerman())
|
|
||||||
* for displayLocale would result in "Englisch". NULL may be used to specify the default.
|
|
||||||
* @return the displayable name for this locale
|
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public String getDisplayName(ULocale displayLocale) {
|
public String getDisplayName(ULocale displayLocale) {
|
||||||
return getDisplayName(localeID, displayLocale.localeID);
|
return getDisplayName(localeID, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the full name suitable for display for the user's default locale.
|
* Return the locale ID localized for display in the provided locale.
|
||||||
* @return the displayable name for this locale
|
* @param localeID the locale whose name is to be displayed.
|
||||||
|
* @param displayLocaleID the id of the locale in which to display the locale name.
|
||||||
|
* @return the localized locale name.
|
||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
*/
|
*/
|
||||||
public static String getDisplayName(String localeID, String displaylocaleID) {
|
public static String getDisplayName(String localeID, String displayLocaleID) {
|
||||||
// TODO: get resource information
|
return getDisplayName(localeID, new ULocale(displayLocaleID));
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the locale ID localized for display in the provided locale.
|
||||||
|
* @param the locale whose name is to be displayed.
|
||||||
|
* @param displayLocale the locale in which to display the locale name.
|
||||||
|
* @return the localized locale name.
|
||||||
|
* @draft ICU 3.0
|
||||||
|
*/
|
||||||
|
public static String getDisplayName(String localeID, ULocale displayLocale) {
|
||||||
|
// the ICU4C code takes care to generate display names when the language is empty,
|
||||||
|
// but i'm not sure when this can happen???
|
||||||
|
|
||||||
|
// lang
|
||||||
|
// lang (script, country, variant, keyword=value, ...)
|
||||||
|
// script, country, variant, keyword=value, ...
|
||||||
|
final String[] tableNames = { "Languages", "Scripts", "Countries", "Variants" };
|
||||||
|
|
||||||
|
IDParser parser = new IDParser(localeID);
|
||||||
|
String[] names = parser.getLanguageScriptCountryVariant();
|
||||||
|
Iterator keys = parser.getKeywordMap().entrySet().iterator();
|
||||||
|
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
boolean haveLanguage = names[0].length() > 0;
|
||||||
|
boolean openParen = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < names.length; ++i) {
|
||||||
|
String name = names[i];
|
||||||
|
if (name.length() > 0) {
|
||||||
|
name = getTableString(tableNames[i], null, name, displayLocale);
|
||||||
|
if (buf.length() > 0) { // need a separator
|
||||||
|
if (haveLanguage & !openParen) {
|
||||||
|
buf.append(" (");
|
||||||
|
openParen = true;
|
||||||
|
} else {
|
||||||
|
buf.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf.append(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
if (buf.length() > 0) {
|
||||||
|
if (haveLanguage & !openParen) {
|
||||||
|
buf.append(" (");
|
||||||
|
openParen = true;
|
||||||
|
} else {
|
||||||
|
buf.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map.Entry e = (Map.Entry)keys.next();
|
||||||
|
String key = (String)e.getKey();
|
||||||
|
String val = (String)e.getValue();
|
||||||
|
buf.append(getTableString("Keys", null, key, displayLocale));
|
||||||
|
buf.append("=");
|
||||||
|
buf.append(getTableString("Types", key, val, displayLocale));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openParen) {
|
||||||
|
buf.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user