src/java.base/share/classes/sun/util/resources/LocaleData.java

Print this page

        

*** 49,58 **** --- 49,59 ---- import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; import sun.util.locale.provider.JRELocaleProviderAdapter; import sun.util.locale.provider.LocaleProviderAdapter; + import sun.util.locale.provider.ResourceBundleBasedAdapter; import static sun.util.locale.provider.LocaleProviderAdapter.Type.CLDR; import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE; /** * Provides information about and access to resource bundles in the
*** 203,222 **** * @returns a list of candidate locales to search from. * @exception NullPointerException if baseName or locale is null. */ @Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { ! List<Locale> candidates = super.getCandidateLocales(baseName, locale); // Weed out Locales which are known to have no resource bundles int lastDot = baseName.lastIndexOf('.'); String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName; - LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE; - LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type); Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category); if (!langtags.isEmpty()) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) { ! if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) { itr.remove(); } } } --- 204,226 ---- * @returns a list of candidate locales to search from. * @exception NullPointerException if baseName or locale is null. */ @Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { ! LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE; ! LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type); ! List<Locale> candidates = adapter instanceof ResourceBundleBasedAdapter ? ! ((ResourceBundleBasedAdapter)adapter).getCandidateLocales(baseName, locale) : ! super.getCandidateLocales(baseName, locale); ! // Weed out Locales which are known to have no resource bundles int lastDot = baseName.lastIndexOf('.'); String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName; Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category); if (!langtags.isEmpty()) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) { ! if (!adapter.isSupportedProviderLocale(itr.next(), langtags)) { itr.remove(); } } }
*** 245,276 **** } private static final String DOTCLDR = ".cldr"; /** ! * Changes baseName to its per-language package name and * calls the super class implementation. For example, * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP, ! * the baseName is changed to "sun.text.resources.ja.FormatData". If * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData", ! * the name is changed to "sun.text.resources.cldr.jp.FormatData". */ @Override public String toBundleName(String baseName, Locale locale) { String newBaseName = baseName; String lang = locale.getLanguage(); if (lang.length() > 0) { if (baseName.startsWith(JRE.getUtilResourcesPackage()) || baseName.startsWith(JRE.getTextResourcesPackage())) { // Assume the lengths are the same. assert JRE.getUtilResourcesPackage().length() == JRE.getTextResourcesPackage().length(); int index = JRE.getUtilResourcesPackage().length(); if (baseName.indexOf(DOTCLDR, index) > 0) { index += DOTCLDR.length(); } ! newBaseName = baseName.substring(0, index + 1) + lang + baseName.substring(index); } } return super.toBundleName(newBaseName, locale); } --- 249,282 ---- } private static final String DOTCLDR = ".cldr"; /** ! * Changes baseName to its per-language/country package name and * calls the super class implementation. For example, * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP, ! * the baseName is changed to "sun.text.resources.ja.JP.FormatData". If * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData", ! * the name is changed to "sun.text.resources.cldr.ja.JP.FormatData". */ @Override public String toBundleName(String baseName, Locale locale) { String newBaseName = baseName; String lang = locale.getLanguage(); + String ctry = locale.getCountry(); if (lang.length() > 0) { if (baseName.startsWith(JRE.getUtilResourcesPackage()) || baseName.startsWith(JRE.getTextResourcesPackage())) { // Assume the lengths are the same. assert JRE.getUtilResourcesPackage().length() == JRE.getTextResourcesPackage().length(); int index = JRE.getUtilResourcesPackage().length(); if (baseName.indexOf(DOTCLDR, index) > 0) { index += DOTCLDR.length(); } ! ctry = (ctry.length() == 2) ? ("." + ctry) : ""; ! newBaseName = baseName.substring(0, index + 1) + lang + ctry + baseName.substring(index); } } return super.toBundleName(newBaseName, locale); }