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

The following are Jave code examples for showing how to use getISOLanguages() 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: oscm   File: BLValidator.java   View Source Code Vote up 6 votes
private static void isLocaleSupported(String member, String value)
        throws ValidationException {
    if (value == null || value.trim().length() == 0) {
        return;
    }

    boolean invalidLocale = true;
    String[] locales = Locale.getISOLanguages();// .getAvailableLocales();
    for (String locale : locales) {
        if (locale.equals(value)) {
            invalidLocale = false;
            break;
        }
    }
    if (invalidLocale) {
        ValidationException vf = new ValidationException(
                ReasonEnum.INVALID_LOCALE, member, new Object[] { value });
        logValidationFailure(vf);
        throw vf;
    }

}
 
Example 2
Project: jdk8u-jdk   File: LocaleTest.java   View Source Code Vote up 6 votes
/**
 * @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 3
Project: jdk8u-jdk   File: Bug6275682.java   View Source Code Vote up 6 votes
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
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 6 votes
/**
 * @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
Project: openjdk-jdk10   File: Bug6275682.java   View Source Code Vote up 6 votes
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 6
Project: VASSAL-src   File: LocaleConfigurer.java   View Source Code Vote up 5 votes
protected String[] getLanguageList() {
  if (languageList == null) {
    String[] langs = Locale.getISOLanguages();
    ArrayList<String> sortedLangs = new ArrayList<String>();
    for (int i = 0; i < langs.length; i++) {
      String lang =
        (new Locale(langs[i])).getDisplayLanguage(Locale.getDefault());
      languages.put(lang, langs[i]);
      sortedLangs.add(lang);
    }
    Collections.sort(sortedLangs, Collator.getInstance(Locale.getDefault()));
    languageList = sortedLangs.toArray(new String[sortedLangs.size()]);
  }
  return languageList;
}
 
Example 7
Project: oscm   File: OperatorServiceLocalBean.java   View Source Code Vote up 5 votes
private boolean checkLocale(String languageISOCode) {
    String[] locales = Locale.getISOLanguages();
    for (String l : locales) {
        if (l.equalsIgnoreCase(languageISOCode)) {
            return true;
        }
    }
    return false;
}
 
Example 8
Project: oscm   File: LocaleUtils.java   View Source Code Vote up 5 votes
public static boolean isLocaleValid(String languageISOCode) {
    String[] locales = Locale.getISOLanguages();
    for (String l : locales) {
        if (l.equalsIgnoreCase(languageISOCode)) {
            return true;
        }
    }
    return false;
}