214 |
getLocale(SystemProperties.getProperty("user.language", "en"), |
getLocale(SystemProperties.getProperty("user.language", "en"), |
215 |
SystemProperties.getProperty("user.region", ""), |
SystemProperties.getProperty("user.region", ""), |
216 |
SystemProperties.getProperty("user.variant", "")); |
SystemProperties.getProperty("user.variant", "")); |
217 |
|
|
218 |
|
/** |
219 |
|
* Array storing all the available two-letter ISO639 languages. |
220 |
|
*/ |
221 |
|
private static transient String[] languageCache; |
222 |
|
|
223 |
|
/** |
224 |
|
* Array storing all the available two-letter ISO3166 country codes. |
225 |
|
*/ |
226 |
|
private static transient String[] countryCache; |
227 |
|
|
228 |
|
/** |
229 |
|
* Retrieves the locale with the specified language from the cache. |
230 |
|
* |
231 |
|
* @param language the language of the locale to retrieve. |
232 |
|
* @return the locale. |
233 |
|
*/ |
234 |
private static Locale getLocale(String language) |
private static Locale getLocale(String language) |
235 |
{ |
{ |
236 |
return getLocale(language, "", ""); |
return getLocale(language, "", ""); |
237 |
} |
} |
238 |
|
|
239 |
|
/** |
240 |
|
* Retrieves the locale with the specified language and region |
241 |
|
* from the cache. |
242 |
|
* |
243 |
|
* @param language the language of the locale to retrieve. |
244 |
|
* @param region the region of the locale to retrieve. |
245 |
|
* @return the locale. |
246 |
|
*/ |
247 |
private static Locale getLocale(String language, String region) |
private static Locale getLocale(String language, String region) |
248 |
{ |
{ |
249 |
return getLocale(language, region, ""); |
return getLocale(language, region, ""); |
250 |
} |
} |
251 |
|
|
252 |
|
/** |
253 |
|
* Retrieves the locale with the specified language, region |
254 |
|
* and variant from the cache. |
255 |
|
* |
256 |
|
* @param language the language of the locale to retrieve. |
257 |
|
* @param region the region of the locale to retrieve. |
258 |
|
* @param variant the variant of the locale to retrieve. |
259 |
|
* @return the locale. |
260 |
|
*/ |
261 |
private static Locale getLocale(String language, String region, String variant) |
private static Locale getLocale(String language, String region, String variant) |
262 |
{ |
{ |
263 |
if (localeMap == null) |
if (localeMap == null) |
422 |
*/ |
*/ |
423 |
public static String[] getISOCountries() |
public static String[] getISOCountries() |
424 |
{ |
{ |
425 |
return new String[] |
if (countryCache == null) |
426 |
{ |
{ |
427 |
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "AS", |
countryCache = getISOStrings("territories"); |
428 |
"AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", |
} |
429 |
"BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", |
|
430 |
"CC", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", |
return countryCache; |
|
"CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", |
|
|
"EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", |
|
|
"GA", "GB", "GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", |
|
|
"GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", |
|
|
"ID", "IE", "IL", "IN", "IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", |
|
|
"KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", |
|
|
"LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", |
|
|
"MD", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", |
|
|
"MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", |
|
|
"NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", |
|
|
"PH", "PK", "PL", "PM", "PN", "PR", "PT", "PW", "PY", "QA", "RE", "RO", |
|
|
"RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", |
|
|
"SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD", "TF", |
|
|
"TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TP", "TR", "TT", "TV", "TW", |
|
|
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", |
|
|
"VN", "VU", "WF", "WS", "YE", "YT", "YU", "ZA", "ZM", "ZR", "ZW" |
|
|
}; |
|
431 |
} |
} |
432 |
|
|
433 |
/** |
/** |
438 |
*/ |
*/ |
439 |
public static String[] getISOLanguages() |
public static String[] getISOLanguages() |
440 |
{ |
{ |
441 |
return new String[] |
if (languageCache == null) |
442 |
{ |
{ |
443 |
"aa", "ab", "af", "am", "ar", "as", "ay", "az", "ba", "be", "bg", "bh", |
languageCache = getISOStrings("languages"); |
444 |
"bi", "bn", "bo", "br", "ca", "co", "cs", "cy", "da", "de", "dz", "el", |
} |
445 |
"en", "eo", "es", "et", "eu", "fa", "fi", "fj", "fo", "fr", "fy", "ga", |
return languageCache; |
446 |
"gd", "gl", "gn", "gu", "ha", "he", "hi", "hr", "hu", "hy", "ia", "id", |
} |
447 |
"ie", "ik", "in", "is", "it", "iu", "iw", "ja", "ji", "jw", "ka", "kk", |
|
448 |
"kl", "km", "kn", "ko", "ks", "ku", "ky", "la", "ln", "lo", "lt", "lv", |
/** |
449 |
"mg", "mi", "mk", "ml", "mn", "mo", "mr", "ms", "mt", "my", "na", "ne", |
* Returns the set of keys from the specified resource hashtable, filtered |
450 |
"nl", "no", "oc", "om", "or", "pa", "pl", "ps", "pt", "qu", "rm", "rn", |
* so that only two letter strings are returned. |
451 |
"ro", "ru", "rw", "sa", "sd", "sg", "sh", "si", "sk", "sl", "sm", "sn", |
* |
452 |
"so", "sq", "sr", "ss", "st", "su", "sv", "sw", "ta", "te", "tg", "th", |
* @param tableName the name of the table from which to retrieve the keys. |
453 |
"ti", "tk", "tl", "tn", "to", "tr", "ts", "tt", "tw", "ug", "uk", "ur", |
* @return an array of two-letter strings. |
454 |
"uz", "vi", "vo", "wo", "xh", "yi", "yo", "za", "zh", "zu" |
*/ |
455 |
}; |
private static String[] getISOStrings(String tableName) |
456 |
|
{ |
457 |
|
List tempList; |
458 |
|
ResourceBundle bundle; |
459 |
|
Enumeration keys; |
460 |
|
int count = 0; |
461 |
|
String[] strings; |
462 |
|
|
463 |
|
tempList = new ArrayList(); |
464 |
|
bundle = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation"); |
465 |
|
keys = ((Hashtable) bundle.getObject(tableName)).keys(); |
466 |
|
while (keys.hasMoreElements()) |
467 |
|
{ |
468 |
|
String nextString; |
469 |
|
|
470 |
|
nextString = (String) keys.nextElement(); |
471 |
|
if (nextString.length() == 2 && |
472 |
|
Character.isLetter(nextString.charAt(0)) && |
473 |
|
Character.isLetter(nextString.charAt(1))) |
474 |
|
{ |
475 |
|
tempList.add(nextString); |
476 |
|
++count; |
477 |
|
} |
478 |
|
} |
479 |
|
strings = new String[count]; |
480 |
|
for (int a = 0; a < count; ++a) |
481 |
|
{ |
482 |
|
strings[a] = (String) tempList.get(a); |
483 |
|
} |
484 |
|
return strings; |
485 |
} |
} |
486 |
|
|
487 |
/** |
/** |