Reputation: 115
I am trying to internationalize my application, and I started practising with the ResourceBundle
and Locale
s 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
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