X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fclasspath%2Fgnu%2Fjava%2Flocale%2FLocaleHelper.java;h=4fefd1639798f338732504bab558155777479718;hb=5bf762459121cc397663d22498d62d71fa179ef6;hp=cec0147179f95aad7136de1ba612413fb33e2ac2;hpb=64089cc9f030d8ef7972adb5d117e0b23f47d62b;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/classpath/gnu/java/locale/LocaleHelper.java b/libjava/classpath/gnu/java/locale/LocaleHelper.java index cec0147179f..4fefd163979 100644 --- a/libjava/classpath/gnu/java/locale/LocaleHelper.java +++ b/libjava/classpath/gnu/java/locale/LocaleHelper.java @@ -55,105 +55,44 @@ import java.util.ResourceBundle; public class LocaleHelper { /** - * This method is used by the localized name lookup methods to retrieve - * the localized name of a particular piece of locale data. - * If the display name can not be localized to the supplied - * locale, it will fall back on other output in the following order: - * - * *

- * If the supplied key is merely the empty string, then the empty string is - * returned. + * This method is used by the localized name lookup methods to + * retrieve the next locale to try. The next locale is derived + * from the supplied locale by applying the first applicable + * rule from the following: + *

+ *
    + *
  1. If the variant contains a '_', then + * this and everything following it is trimmed.
  2. + *
  3. If the variant is non-empty, it is converted to + * an empty string.
  4. + *
  5. If the country is non-empty, it is converted to + * an empty string.
  6. + *
  7. If the language is non-empty, it is converted to + * an empty string (forming {@link java.util.Locale#ROOT})
  8. + *
+ *

+ * The base fallback locale is {@link java.util.Locale#ROOT}. *

* - * @param inLocale the locale to use for formatting the display string. - * @param key the locale data used as a key to the localized lookup tables. - * @param name the name of the hashtable containing the localized data. - * @param checkEnglish true if the method should fall back on data - * from the English locale. - * @param checkRoot true if the method should fall back on data from the - * unlocalized root locale. - * @return a String, hopefully containing the localized - * variant of the input data. - * @throws NullPointerException if inLocale is null. + * @param locale the locale for which a localized piece of + * data could not be obtained. + * @return the next fallback locale to try. */ - public static String getLocalizedString(Locale inLocale, String key, - String name, boolean checkEnglish, - boolean checkRoot) + public static Locale getFallbackLocale(Locale locale) { - String localizedString; - String property; - - if (key.equals("")) - return ""; - property = name + "." + key; - /* Localize to inLocale */ - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - inLocale).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - /* Localize to default locale */ - if (localizedString == null) - { - try - { - ResourceBundle bundle; - - bundle = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation"); - localizedString = bundle.getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Localize to English */ - if (localizedString == null && checkEnglish) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - Locale.ENGLISH).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return unlocalized version */ - if (localizedString == null && checkRoot) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - new Locale("","","") - ).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return original input string */ - if (localizedString == null) - { - localizedString = key; - } - return localizedString; + String language = locale.getLanguage(); + String country = locale.getCountry(); + String variant = locale.getVariant(); + int uscore = variant.indexOf('_'); + if (uscore != -1) + return new Locale(language, country, + variant.substring(0, uscore)); + if (!variant.isEmpty()) + return new Locale(language, country, ""); + if (!country.isEmpty()) + return new Locale(language, "", ""); + return Locale.ROOT; } /**