padro
padro

Reputation: 115

ResourceBundle getLocale().getDisplayLanguage() returns empty String

I am trying to internationalize my application, and I started practising with the ResourceBundle and Locales with a simple function that creates a ResourceBundle rb with the default Locale of the machine and after it prints the language:

private void loadView() {
    ResourceBundle rb = ResourceBundle.getBundle("languages_"+Locale.getDefault());
    System.out.println("Language: "+rb.getLocale().getDisplayLanguage());
}

I have different resource bundle properties files starting with languages_: Properties files

When I call the function loadView it does not print the language. It prints nothing.

What can be the problem?

Upvotes: 1

Views: 525

Answers (1)

Karol Dowbecki
Karol Dowbecki

Reputation: 44960

Your code should either don't specify locale at all to allow Java to resolve the current one

ResourceBundle rb = ResourceBundle.getBundle("languages");

or use the Locale parameter instead of string concatenation

ResourceBundle rb = ResourceBundle.getBundle("languages", Locale.getDefault());

Upvotes: 1

Related Questions