Java Code Examples for java.util.Locale#getISOLanguages()

The following examples show how to use java.util.Locale#getISOLanguages() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug6275682.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 2
Source File: Util.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static HashMap<String, String> createIso3ToIso2Map() {
  String[] iso2Languages = Locale.getISOLanguages();
  HashMap<String, String> iso3ToIso2 =
      new HashMap<>(
          /* initialCapacity= */ iso2Languages.length + iso3BibliographicalToIso2.length);
  for (String iso2 : iso2Languages) {
    try {
      // This returns the ISO 639-2/T code for the language.
      String iso3 = new Locale(iso2).getISO3Language();
      if (!TextUtils.isEmpty(iso3)) {
        iso3ToIso2.put(iso3, iso2);
      }
    } catch (MissingResourceException e) {
      // Shouldn't happen for list of known languages, but we don't want to throw either.
    }
  }
  // Add additional ISO 639-2/B codes to mapping.
  for (int i = 0; i < iso3BibliographicalToIso2.length; i += 2) {
    iso3ToIso2.put(iso3BibliographicalToIso2[i], iso3BibliographicalToIso2[i + 1]);
  }
  return iso3ToIso2;
}
 
Example 3
Source File: Bug6275682.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 4
Source File: LocaleTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 5
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static HashMap<String, String> createIso3ToIso2Map() {
  String[] iso2Languages = Locale.getISOLanguages();
  HashMap<String, String> iso3ToIso2 =
      new HashMap<>(
          /* initialCapacity= */ iso2Languages.length + iso3BibliographicalToIso2.length);
  for (String iso2 : iso2Languages) {
    try {
      // This returns the ISO 639-2/T code for the language.
      String iso3 = new Locale(iso2).getISO3Language();
      if (!TextUtils.isEmpty(iso3)) {
        iso3ToIso2.put(iso3, iso2);
      }
    } catch (MissingResourceException e) {
      // Shouldn't happen for list of known languages, but we don't want to throw either.
    }
  }
  // Add additional ISO 639-2/B codes to mapping.
  for (int i = 0; i < iso3BibliographicalToIso2.length; i += 2) {
    iso3ToIso2.put(iso3BibliographicalToIso2[i], iso3BibliographicalToIso2[i + 1]);
  }
  return iso3ToIso2;
}
 
Example 6
Source File: LocaleTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 7
Source File: Bug6275682.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 8
Source File: LocaleTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 9
Source File: LocaleTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!")) {
        errln("Changed internal country code list!");
    }

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) { // Fixed typo
        errln("Changes internal language code list!");
    }
}
 
Example 10
Source File: IdentifyMovieFragment.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
public LanguageAdapter() {

            mInflater = LayoutInflater.from(getActivity());

            mSystemLocales = Locale.getAvailableLocales();
            String[] languageCodes = Locale.getISOLanguages();

            ArrayList<Locale> mTemp = new ArrayList<Locale>();
            for (String code : languageCodes) {
                if (code.length() == 2) { // We're only interested in two character codes
                    Locale l = new Locale(code);
                    if (hasLocale(l))
                        mTemp.add(l);
                }
            }

            Collections.sort(mTemp, new Comparator<Locale>() {
                @Override
                public int compare(Locale lhs, Locale rhs) {
                    return lhs.getDisplayLanguage(Locale.getDefault()).compareToIgnoreCase(rhs.getDisplayLanguage(Locale.getDefault()));
                }
            });

            mLocales = new ArrayList<Locale>(mTemp);
        }
 
Example 11
Source File: Bug6275682.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 12
Source File: LocaleTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 13
Source File: IdentifyTvShowFragment.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
public LanguageAdapter() {

            mInflater = LayoutInflater.from(getActivity());

            mSystemLocales = Locale.getAvailableLocales();
            String[] languageCodes = Locale.getISOLanguages();

            ArrayList<Locale> mTemp = new ArrayList<Locale>();
            for (String code : languageCodes) {
                if (code.length() == 2) { // We're only interested in two character codes
                    Locale l = new Locale(code);
                    if (hasLocale(l))
                        mTemp.add(l);
                }
            }

            Collections.sort(mTemp, new Comparator<Locale>() {
                @Override
                public int compare(Locale lhs, Locale rhs) {
                    return lhs.getDisplayLanguage(Locale.getDefault()).compareToIgnoreCase(rhs.getDisplayLanguage(Locale.getDefault()));
                }
            });

            mLocales = new ArrayList<Locale>(mTemp);
        }
 
Example 14
Source File: Bug6275682.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 15
Source File: LocaleTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * java.util.Locale#getISOLanguages()
 */
public void test_getISOLanguages() {
    // Test for method java.lang.String []
    // java.util.Locale.getISOLanguages()
    // Assumes always at least 131 ISOlanguages...
    String[] isoLang = Locale.getISOLanguages();
    int length = isoLang.length;

    // BEGIN android-changed
    // Language codes are 2- and 3-letter, with preference given
    // to 2-letter codes where possible. 3-letter codes are used
    // when lack a 2-letter equivalent.
    assertTrue("Random element in wrong format.",
               (isoLang[length / 2].length() == 2 || isoLang[length / 2].length() == 3)
               && isoLang[length / 2].toLowerCase().equals(isoLang[length / 2]));
    // END android-changed

    assertTrue("Wrong number of ISOLanguages.", length > 130);
}
 
Example 16
Source File: LocaleTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 17
Source File: Util.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static HashMap<String, String> createIso3ToIso2Map() {
  String[] iso2Languages = Locale.getISOLanguages();
  HashMap<String, String> iso3ToIso2 =
      new HashMap<>(
          /* initialCapacity= */ iso2Languages.length + iso3BibliographicalToIso2.length);
  for (String iso2 : iso2Languages) {
    try {
      // This returns the ISO 639-2/T code for the language.
      String iso3 = new Locale(iso2).getISO3Language();
      if (!TextUtils.isEmpty(iso3)) {
        iso3ToIso2.put(iso3, iso2);
      }
    } catch (MissingResourceException e) {
      // Shouldn't happen for list of known languages, but we don't want to throw either.
    }
  }
  // Add additional ISO 639-2/B codes to mapping.
  for (int i = 0; i < iso3BibliographicalToIso2.length; i += 2) {
    iso3ToIso2.put(iso3BibliographicalToIso2[i], iso3BibliographicalToIso2[i + 1]);
  }
  return iso3ToIso2;
}
 
Example 18
Source File: OperatorServiceLocalBean.java    From development with Apache License 2.0 5 votes vote down vote up
private boolean checkLocale(String languageISOCode) {
    String[] locales = Locale.getISOLanguages();
    for (String l : locales) {
        if (l.equalsIgnoreCase(languageISOCode)) {
            return true;
        }
    }
    return false;
}
 
Example 19
Source File: LocaleUtils.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Provides the list of languages fetched from the system.
 *
 * @return A list of {@link FormOption} containing language names and their codes.
 */
public static List<FormOption> getLanguages() {
    final List<FormOption> languages = new ArrayList<>();
    for (String languageCode : Locale.getISOLanguages()) {
        try {
            final String languageName = getLanguageNameFromCode(languageCode);
            /*
            Ignore language codes that don't translate to a proper language name. This can be
            detected by case-sensitive matching of the code with its language name
            i.e. if both are same, its not a valid language.
            For example: language names like aa, ace, ada, ady, ae etc.

            This exemption is necessary because of following excerpt found inside
            Locale.getISOLanguages() function's javadoc:
            "The list returned by this method does not contain ALL valid codes that can be used
            to create Locales."

            ### Special case ###
            zxx = No linguistic content.
            */
            if (!languageCode.equals(languageName) && !languageCode.equals("zxx")) {
                languages.add(new FormOption(languageName, languageCode));
            }
        } catch (InvalidLocaleException e) {
            e.printStackTrace();
        }
    }
    sortBasedOnLocale(languages);
    return languages;
}
 
Example 20
Source File: LanguageDetector.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Locale to ISO.
 *
 * @return map containing ISO : locale pairs
 */
public static Map<String, Locale> localeToISO() {
	String[] languages = Locale.getISOLanguages();
	Map<String, Locale> localeMap = new HashMap<String, Locale>(languages.length);
	for (String language : languages) {
		Locale locale = new Locale(language);
		localeMap.put(locale.getISO3Language(), locale);
	}
	return localeMap;
}