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 Here is an example that show how to get all supported language’s code.

package org.kodejava.example.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 a some of the results produces by the code above:

Locale name: Japanese (Japan) = ja_JP
Locale name: Spanish (Peru) = es_PE
Locale name: English (United States) = en_US
Locale name: French (Belgium) = fr_BE
Locale name: Indonesian (Indonesia) = in_ID
Locale name: German (Germany) = de_DE
Locale name: English (Singapore) = en_SG

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.