Search code examples
javastringspring-mvclocalizationlocale

How to Make Localized Strings for Locale Names?


First of all, I realize that you can get all of the locales in Java via the Locale.getAllLocales() method. I'm using Spring MVC.

I'm trying to put all of these Locale's descriptive names ("Language (Country)") into a select drop-down box on my website. However, I need these names to be localized strings so that they change depending on your browser's Locale. Is there already a quick way to do this using Java's Locale class? Or will I need to actually create every single one myself using 's in a property file and define each one in an enum class?

Or maybe an there's an easier way to manually create them?

Thanks!


Solution

  • You can try doing the following

    System.out.println(Locale.GERMANY.getDisplayCountry(Locale.GERMANY));
    

    prints

    Deutschland
    

    I guess this will work for built-in locales, but probably not for custom ones.