本文整理匯總了Java中java.util.Locale.getAvailableLocales方法的典型用法代碼示例。如果您正苦於以下問題:Java Locale.getAvailableLocales方法的具體用法?Java Locale.getAvailableLocales怎麽用?Java Locale.getAvailableLocales使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Locale
的用法示例。
在下文中一共展示了Locale.getAvailableLocales方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) {
String thisFile = "" +
new java.io.File(System.getProperty("test.src", "."),
"VerifyLocale.java");
for (Locale loc : Locale.getAvailableLocales()) {
language = loc.getLanguage();
country = loc.getCountry();
variant = loc.getVariant();
if (!language.equals("")) {
String[] command_line = {
// jumble the options in some weird order
"-doclet", "VerifyLocale",
"-locale", language + (country.equals("") ? "" : ("_" + country + (variant.equals("") ? "" : "_" + variant))),
"-docletpath", System.getProperty("test.classes", "."),
thisFile
};
if (jdk.javadoc.internal.tool.Main.execute(command_line) != 0)
throw new Error("Javadoc encountered warnings or errors.");
}
}
}
示例2: findLocale
import java.util.Locale; //導入方法依賴的package包/類
private static Locale findLocale(String lang) {
Locale[] check;
for (int set = 0; set < 2; set++) {
if (set == 0)
check = new Locale[] { Locale.getDefault(), Locale.ENGLISH };
else
check = Locale.getAvailableLocales();
for (int i = 0; i < check.length; i++) {
Locale loc = check[i];
if (loc != null && loc.getLanguage().equals(lang)) {
return loc;
}
}
}
return null;
}
示例3: initializeCountryPicker
import java.util.Locale; //導入方法依賴的package包/類
/**
* Initializes the country picker with a list of all valid world countries, as obtained by the
* Java locale class.
*/
private void initializeCountryPicker() {
countries = FXCollections.observableArrayList();
Locale[] locales = Locale.getAvailableLocales();
for (Locale locale : locales) {
String name = locale.getDisplayCountry();
if (!countries.contains(name)) {
countries.add(name);
}
}
FXCollections.sort(countries);
countryPicker.setItems(countries);
}
示例4: doOutputFor
import java.util.Locale; //導入方法依賴的package包/類
public static void doOutputFor(String packageName,
String resourceBundleName, PrintStream out)
throws Exception {
Locale[] availableLocales = Locale.getAvailableLocales();
ResourceBundle bundle = ResourceBundle.getBundle(packageName +
resourceBundleName, new Locale("", "", ""));
dumpResourceBundle(resourceBundleName + "/", bundle, out);
for (int i = 0; i < availableLocales.length; i++) {
bundle = ResourceBundle.getBundle(packageName + resourceBundleName,
availableLocales[i]);
dumpResourceBundle(resourceBundleName + "/" + availableLocales[i].toString(),
bundle, out);
}
}
示例5: searchLocale
import java.util.Locale; //導入方法依賴的package包/類
/**
* Search the locale for specified language, specified country and
* specified variant.
*/
private Locale searchLocale(String language, String country,
String variant) {
for (Locale loc : Locale.getAvailableLocales()) {
if (loc.getLanguage().equals(language) &&
(country == null || loc.getCountry().equals(country)) &&
(variant == null || loc.getVariant().equals(variant))) {
return loc;
}
}
return null;
}
示例6: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Locale[] systemLocales = Locale.getAvailableLocales();
if (systemLocales.length == 0)
throw new Exception("Available locale list is empty!");
System.out.println("Found " + systemLocales.length + " locales:");
Locale[] locales = new Locale[systemLocales.length];
for (int i = 0; i < locales.length; i++) {
Locale lowest = null;
for (int j = 0; j < systemLocales.length; j++) {
if (i > 0 && locales[i - 1].toString().compareTo(systemLocales[j].toString()) >= 0)
continue;
if (lowest == null || systemLocales[j].toString().compareTo(lowest.toString()) < 0)
lowest = systemLocales[j];
}
locales[i] = lowest;
}
for (int i = 0; i < locales.length; i++) {
if (locales[i].getCountry().length() == 0)
System.out.println(" " + locales[i].getDisplayLanguage() + ":");
else {
if (locales[i].getVariant().length() == 0)
System.out.println(" " + locales[i].getDisplayCountry());
else
System.out.println(" " + locales[i].getDisplayCountry() + ", "
+ locales[i].getDisplayVariant());
}
}
}
示例7: data
import java.util.Locale; //導入方法依賴的package包/類
@Parameters
public static Set<Locale[]> data() {
Set<Locale[]> localeSet = new HashSet<>();
for (Locale locale : Locale.getAvailableLocales()) {
localeSet.add(new Locale[]{locale});
}
return localeSet;
}
示例8: printLocales
import java.util.Locale; //導入方法依賴的package包/類
private static void printLocales() {
Locale[] tlocales = Locale.getAvailableLocales();
final int len = tlocales == null ? 0 : tlocales.length;
if (len < 1 ) {
return;
}
// Locale does not implement Comparable so we convert it to String
// and sort it for pretty printing.
Set<String> sortedSet = new TreeSet<>();
for (Locale l : tlocales) {
sortedSet.add(l.toString());
}
ostream.print(INDENT + "available locales = ");
Iterator<String> iter = sortedSet.iterator();
final int last = len - 1;
for (int i = 0 ; iter.hasNext() ; i++) {
String s = iter.next();
ostream.print(s);
if (i != last) {
ostream.print(", ");
}
// print columns of 8
if ((i + 1) % 8 == 0) {
ostream.println();
ostream.print(INDENT + INDENT);
}
}
}
示例9: TestBug4135316
import java.util.Locale; //導入方法依賴的package包/類
/**
* @bug 4135316
*/
public void TestBug4135316() {
Locale[] locales1 = Locale.getAvailableLocales();
Locale[] locales2 = Locale.getAvailableLocales();
if (locales1 == locales2)
errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
}
示例10: setLocale
import java.util.Locale; //導入方法依賴的package包/類
static boolean setLocale(Locale desired) {
if (Locale.getDefault().equals(desired)) {
return true; // already set nothing more
}
for (Locale l : Locale.getAvailableLocales()) {
if (l == desired) {
Locale.setDefault(l);
return true;
}
}
return false;
}
示例11: TestGetAvailableLocales
import java.util.Locale; //導入方法依賴的package包/類
/**
* @bug 4107014
*/
public void TestGetAvailableLocales() {
Locale[] locales = Locale.getAvailableLocales();
if (locales == null || locales.length == 0) {
errln("Locale.getAvailableLocales() returned no installed locales!");
} else {
logln("Locale.getAvailableLocales() returned a list of " + locales.length + " locales.");
for (int i = 0; i < locales.length; i++) {
logln(locales[i].toString());
}
}
}
示例12: testRequiredLocales
import java.util.Locale; //導入方法依賴的package包/類
private static boolean testRequiredLocales() {
boolean pass = true;
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
Calendar calendar = Calendar.getInstance(Locale.US);
calendar.clear();
calendar.set(2001, 4, 10, 12, 0, 0);
Date date = calendar.getTime();
Locale[] available = Locale.getAvailableLocales();
for (int i = 0; i < requiredLocales.length; i++) {
Locale locale = requiredLocales[i];
boolean found = false;
for (int j = 0; j < available.length; j++) {
if (available[j].equals(locale)) {
found = true;
break;
}
}
if (!found) {
System.out.println("Locale not available: " + locale);
pass = false;
} else {
DateFormat format =
DateFormat.getDateInstance(DateFormat.FULL, locale);
String dateString = format.format(date);
if (!dateString.equals(requiredLocaleDates[i])) {
System.out.println("Incorrect date string for locale "
+ locale + ". Expected: " + requiredLocaleDates[i]
+ ", got: " + dateString);
pass = false;
}
}
}
return pass;
}
示例13: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String args[])
throws Exception {
Locale reservedLocale = Locale.getDefault();
try {
/**
* Test cases:
* 1) Same RDNs.
* 2) same RDN sequence with an AVA ordered differently.
* 3) RDN sequences of a differing AVA.
* 4) RDN sequence of different length.
* 5) RDN sequence of different Case.
* 6) Matching binary return values.
* 7) Binary values that don't match.
*/
String names1[] = new String [] {
"ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob",
"ou=Sales+cn=Scott+c=US", "cn=config"};
String names2[] = new String [] {
"ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott",
"ou=Sales+cn=Scott", "Cn=COnFIG"};
int expectedResults[] = {0, 0, -1, -1, 0};
for (Locale locale : Locale.getAvailableLocales()) {
// reset the default locale
Locale.setDefault(locale);
for (int i = 0; i < names1.length; i++) {
checkResults(new LdapName(names1[i]),
new LdapName(names2[i]), expectedResults[i]);
}
byte[] value = "abcxyz".getBytes();
Rdn rdn1 = new Rdn("binary", value);
ArrayList rdns1 = new ArrayList();
rdns1.add(rdn1);
LdapName l1 = new LdapName(rdns1);
Rdn rdn2 = new Rdn("binary", value);
ArrayList rdns2 = new ArrayList();
rdns2.add(rdn2);
LdapName l2 = new LdapName(rdns2);
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797A");
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797B");
checkResults(l1, l2, -1);
System.out.println("Tests passed");
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}
示例14: testSupportedLocales
import java.util.Locale; //導入方法依賴的package包/類
@Test
public void testSupportedLocales() {
for (Locale loc:Locale.getAvailableLocales()) {
testLocale(loc);
}
}
示例15: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {
boolean localeAvailable = false;
for (Locale l : Locale.getAvailableLocales()) {
if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) {
localeAvailable = true;
break;
}
}
if (!localeAvailable) {
System.out.println("Warning: locale: " + Locale.JAPAN
+ " not found, test passes vacuously");
return;
}
if ("C".equals(LC_ALL) || "C".equals(LANG)) {
System.out.println("Warning: The LANG and/or LC_ALL env vars are " +
"set to \"C\":\n" +
" LANG=" + LANG + "\n" +
" LC_ALL=" + LC_ALL + "\n" +
"This test requires support for multi-byte filenames.\n" +
"Test passes vacuously.");
return;
}
if (encoding.equals("MS932") || encoding.equals("UTF-8")) {
Locale.setDefault(Locale.JAPAN);
System.out.println("using locale " + Locale.JAPAN +
", encoding " + encoding);
} else {
System.out.println("Warning: current encoding is " + encoding +
"this test requires MS932 <Ja> or UTF-8," +
" test passes vacuously");
return;
}
dir.mkdir();
File dirfile = new File(dir, "foo.jar");
createJar(dirfile,
"public static void main(String... args) {",
"System.out.println(\"Hello World\");",
"System.exit(0);",
"}");
// remove the class files, to ensure that the class is indeed picked up
// from the jar file and not from ambient classpath.
File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT));
for (File f : classFiles) {
f.delete();
}
// test with a jar file
TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath());
System.out.println(tr);
if (!tr.isOK()) {
throw new RuntimeException("TEST FAILED");
}
// test the same class but by specifying it as a classpath
tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo");
System.out.println(tr);
if (!tr.isOK()) {
throw new RuntimeException("TEST FAILED");
}
}