jdk/src/share/classes/sun/util/resources/LocaleData.java
changeset 8695 e83968c6ceda
parent 6501 684810d882b3
child 9035 1255eb81cc2f
equal deleted inserted replaced
8250:a36beda9b9de 8695:e83968c6ceda
   169          public List<Locale> getCandidateLocales(String baseName, Locale locale) {
   169          public List<Locale> getCandidateLocales(String baseName, Locale locale) {
   170             List<Locale> candidates = super.getCandidateLocales(baseName, locale);
   170             List<Locale> candidates = super.getCandidateLocales(baseName, locale);
   171             /* Get the locale string list from LocaleDataMetaInfo class. */
   171             /* Get the locale string list from LocaleDataMetaInfo class. */
   172             String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName);
   172             String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName);
   173 
   173 
   174             if (localeString.length() == 0) {
   174       if (localeString.length() == 0) {
   175                 return candidates;
   175                 return candidates;
   176             }
   176             }
   177 
   177 
   178             for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) {
   178             for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) {
   179                 String lstr = l.next().toString();
   179                 Locale loc = l.next();
   180                 /* truncate extra segment introduced by Java 7 for script and extesions */
   180                 String lstr = null;
   181                 int idx = lstr.indexOf("_#");
   181                 if (loc.getScript().length() > 0) {
   182                 if (idx >= 0) {
   182                     lstr = loc.toLanguageTag().replace('-', '_');
   183                     lstr = lstr.substring(0, idx);
   183                 } else {
       
   184                     lstr = loc.toString();
       
   185                     int idx = lstr.indexOf("_#");
       
   186                     if (idx >= 0) {
       
   187                         lstr = lstr.substring(0, idx);
       
   188                     }
   184                 }
   189                 }
   185                 /* Every locale string in the locale string list returned from
   190                 /* Every locale string in the locale string list returned from
   186                    the above getSupportedLocaleString is enclosed
   191                    the above getSupportedLocaleString is enclosed
   187                    within two white spaces so that we could check some locale
   192                    within two white spaces so that we could check some locale
   188                    such as "en".
   193                    such as "en".
   263                 StringTokenizer(supportedLocaleString.substring(0, barIndex));
   268                 StringTokenizer(supportedLocaleString.substring(0, barIndex));
   264         }
   269         }
   265 
   270 
   266         Locale[] locales = new Locale[localeStringTokenizer.countTokens()];
   271         Locale[] locales = new Locale[localeStringTokenizer.countTokens()];
   267         for (int i = 0; i < locales.length; i++) {
   272         for (int i = 0; i < locales.length; i++) {
   268             String currentToken = localeStringTokenizer.nextToken();
   273             String currentToken = localeStringTokenizer.nextToken().replace('_','-');
   269             int p2 = 0;
   274             if (currentToken.equals("ja-JP-JP")) {
   270             int p1 = currentToken.indexOf('_');
   275                 currentToken = "ja-JP-u-ca-japanese-x-lvariant-JP";
   271             String language = "";
   276             } else if (currentToken.equals("th-TH-TH")) {
   272             String country = "";
   277                 currentToken = "th-TH-u-nu-thai-x-lvariant-TH";
   273             String variant = "";
   278             } else if (currentToken.equals("no-NO-NY")) {
   274 
   279                 currentToken = "no-NO-x-lvariant-NY";
   275             if (p1 == -1) {
   280             }
   276                 language = currentToken;
   281             locales[i] = Locale.forLanguageTag(currentToken);
   277             } else {
       
   278                 language = currentToken.substring(0, p1);
       
   279                 p2 = currentToken.indexOf('_', p1 + 1);
       
   280                 if (p2 == -1) {
       
   281                     country = currentToken.substring(p1 + 1);
       
   282                 } else {
       
   283                     country = currentToken.substring(p1 + 1, p2);
       
   284                     if (p2 < currentToken.length()) {
       
   285                         variant = currentToken.substring(p2 + 1);
       
   286                     }
       
   287                 }
       
   288             }
       
   289             locales[i] = new Locale(language, country, variant);
       
   290         }
   282         }
   291         return locales;
   283         return locales;
   292     }
   284     }
   293 
   285 
   294 }
   286 }