January 3, 2017

Internationalization (i18n) with ResourceBundle and Properties

To externalize local messages, Java have the java.util.ResourceBundle class.

Create a properties file for the default locale. Then create a new properties for each locale with the suffix _<language>_<COUNTRY>, in the same way you initialize java.util.Locale.Locale(String, String).

Example

To load the localized text, use java.util.ResourceBundle.getString(String).

Example

messages.properties

messages_sv_SE.properties

And the Java code to load them.

Output

No comments: