javalocale

java.util.Locale does not recognize Austria


Would need help in identifying what is the locale id for Austria. I have tried with de_AT/at/at_at as mentioned here

But it seems Locale API doesn't recognize these locale, any pointers..?

Exception when trying with de_AT:

java.util.MissingResourceException: Couldn't find 3-letter language code for de_at
    at java.util.Locale.getISO3Language(Unknown Source)
    at com.test.rupesh.CQInstanceHelper.language(Main.java:74)
    at com.test.rupesh.Main.main(Main.java:20)

Solution

  • What are you trying with de_AT exactly?

    Locale austria = new Locale("de", "AT");
    System.out.println("Locale=" + austria);
    System.out.println("ISO3 language=" + austria.getISO3Language());
    

    prints out:

    Locale=de_AT
    ISO3 language=deu
    

    EDIT: Do not instantiate locales this way:

    Locale austria = new Locale("de_AT");
    System.out.println("Locale=" + austria);
    System.out.println("ISO3 language=" + austria.getISO3Language());
    

    prints out:

    Locale=de_at
    Exception in thread "main" java.util.MissingResourceException: Couldn't find 3-letter language code for de_at
        at java.util.Locale.getISO3Language(Locale.java:568)
        at Scribble.main(Test.java:10)