当前位置: 首页>>代码示例>>Java>>正文


Java Locale.getAvailableLocales方法代码示例

本文整理汇总了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.");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:VerifyLocale.java

示例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;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:17,代码来源:AppPreferences.java

示例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);
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:17,代码来源:PlaceBookingScreenController.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:GenerateKeyList.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DocLocale.java

示例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());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:bug4122700.java

示例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;
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:9,代码来源:BtcFormatTest.java

示例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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:LauncherHelper.java

示例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!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:LocaleTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:UnicodeTest.java

示例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());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LocaleTest.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:InternationalBAT.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:59,代码来源:CompareToEqualsTests.java

示例14: testSupportedLocales

import java.util.Locale; //导入方法依赖的package包/类
@Test
public void testSupportedLocales() {
    for (Locale loc:Locale.getAvailableLocales()) {
        testLocale(loc);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:Bug8139107.java

示例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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:62,代码来源:I18NJarTest.java


注:本文中的java.util.Locale.getAvailableLocales方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。