Java Code Examples for java.util.Locale.getAvailableLocales()

The following are Jave code examples for showing how to use getAvailableLocales() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: VerifyLocale.java   View Source Code Vote up 6 votes
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.");
        }
    }
}
 
Example 2
Project: Logisim   File: AppPreferences.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: git-rekt   File: PlaceBookingScreenController.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 4
Project: jdk8u-jdk   File: GenerateKeyList.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 5
Project: openjdk-jdk10   File: DocLocale.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 6
Project: jdk8u-jdk   File: bug4122700.java   View Source Code Vote up 5 votes
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());
        }
    }
}
 
Example 7
Project: creacoinj   File: BtcFormatTest.java   View Source Code Vote up 5 votes
@Parameters
public static Set<Locale[]> data() {
    Set<Locale[]> localeSet = new HashSet<>();
    for (Locale locale : Locale.getAvailableLocales()) {
        localeSet.add(new Locale[]{locale});
    }
    return localeSet;
}
 
Example 8
Project: openjdk-jdk10   File: LauncherHelper.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 9
Project: jdk8u-jdk   File: LocaleTest.java   View Source Code Vote up 5 votes
/**
 * @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!");
}
 
Example 10
Project: openjdk-jdk10   File: UnicodeTest.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 5 votes
/**
 * @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());
        }
    }
}
 
Example 12
Project: jdk8u-jdk   File: InternationalBAT.java   View Source Code Vote up 5 votes
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;
}
 
Example 13
Project: openjdk-jdk10   File: GenerateKeyList.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 14
Project: jdk8u-jdk   File: UnicodeTest.java   View Source Code Vote up 5 votes
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;
}
 
Example 15
Project: jdk8u-jdk   File: CompareToEqualsTests.java   View Source Code Vote up 4 votes
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);
    }
}
 
Example 16
Project: jdk8u-jdk   File: Bug8139107.java   View Source Code Vote up 4 votes
@Test
public void testSupportedLocales() {
    for (Locale loc:Locale.getAvailableLocales()) {
        testLocale(loc);
    }
}
 
Example 17
Project: jdk8u-jdk   File: I18NJarTest.java   View Source Code Vote up 4 votes
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");
    }
}
 
Example 18
Project: openjdk-jdk10   File: LocaleDependentURLTest.java   View Source Code Vote up 4 votes
public static void main(String args[]) throws MalformedURLException {
    for (Locale locale : Locale.getAvailableLocales()) {
        Locale.setDefault(locale);
        new URL("FILE:///TMP/X");
    }
}
 
Example 19
Project: FindCurrencyExa   File: MainFragment.java   View Source Code Vote up 4 votes
@TargetApi(Build.VERSION_CODES.N)
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.btn_find:
            String loc = et_location_name.getText().toString().trim();
            String countryCode = et_country_code.getText().toString().trim();
            String countryISOCode = et_countyISO.getText().toString().trim();
            String currencyCode = et_currencyCode.getText().toString().trim();

            if (!loc.trim().equalsIgnoreCase("") || !countryCode.trim().equalsIgnoreCase("") || !countryISOCode.trim().equalsIgnoreCase("")) {
                Locale[] locs = Locale.getAvailableLocales();
                for (Locale locale : locs) {
                    try {
                        if (locale.getDisplayCountry().equalsIgnoreCase(loc) || locale.getCountry().equalsIgnoreCase(countryCode) ||
                                locale.getISO3Country().equalsIgnoreCase(countryISOCode)) {
                            //hideNoDataFound();
                            tv_currencySymbol.setText(Currency.getInstance(locale).getSymbol());
                            tv_currencyDisplayName.setText("Display Name: ".concat(Currency.getInstance(locale).getDisplayName()));
                            tv_currencyCode.setText("Currency Code: ".concat(Currency.getInstance(locale).getCurrencyCode()));
                            tv_fractionDigits.setText("Fraction Digits: ".concat(String.valueOf(Currency.getInstance(locale).getDefaultFractionDigits())));
                            tv_numericCode.setText("Numeric Code: ".concat(String.valueOf(Currency.getInstance(locale).getNumericCode())));
                        } else {
                            //showNoDataFound();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else if (!currencyCode.equalsIgnoreCase(null) || !currencyCode.equalsIgnoreCase("")) {
                for (int i = 0; i < currencyList.size(); i++) {
                    if (currencyList.get(i).getCurrencyCode().equalsIgnoreCase(currencyCode)) {
                        //hideNoDataFound();
                        tv_currencySymbol.setText(currencyList.get(i).getSymbol());
                        tv_currencyDisplayName.setText("Display Name: ".concat(currencyList.get(i).getDisplayName()));
                        tv_currencyCode.setText("Currency Code: ".concat(currencyList.get(i).getCurrencyCode()));
                        tv_fractionDigits.setText("Fraction Digits: ".concat(String.valueOf(currencyList.get(i).getDefaultFractionDigits())));
                        tv_numericCode.setText("Numeric Code: ".concat(String.valueOf(currencyList.get(i).getNumericCode())));
                    } else {
                        //showNoDataFound();
                    }
                }
            }
            break;
    }
}
 
Example 20
Project: openjdk-jdk10   File: Bug8139107.java   View Source Code Vote up 4 votes
@Test
public void testSupportedLocales() {
    for (Locale loc:Locale.getAvailableLocales()) {
        testLocale(loc);
    }
}