How do I get all available Locale language codes?

When you want to internationalize your application, you need to know the language code and country code. These codes will be used as the properties file name (the file name must be ended in language_COUNTRY.properties). Here is an example that show how to get all supported language’s code.

package org.kodejava.util;

import java.util.Locale;

public class LocaleCountryLanguageCode {
    public static void main(String[] args) {
        // Gets an array of all installed locales. The returned array represents
        // the union of locales supported by the Java runtime environment and by 
        // installed LocaleServiceProvider implementations.
        Locale[] locales = Locale.getAvailableLocales();

        for (Locale locale : locales) {
            System.out.printf("Locale name: %s = %s_%s%n",
                    locale.getDisplayName(), locale.getLanguage(), locale.getCountry());
        }
    }
}

Here are some of the results produces by the code above:

...
Locale name: Kikuyu (Latin, Kenya) = ki_KE
Locale name: Spanish (Brazil) = es_BR
Locale name: Koyra Chiini (Mali) = khq_ML
Locale name: English (Solomon Islands) = en_SB
Locale name: Tibetan (Tibetan, China) = bo_CN
Locale name: Cherokee (United States) = chr_US
Locale name: Kinyarwanda (Rwanda) = rw_RW
Locale name: Tachelhit (Tifinagh, Morocco) = shi_MA
Locale name: Arabic (Iraq) = ar_IQ
Locale name: Nyankole = nyn_
...