|
Java™ by example!
|
|
|
How do I localize my log messages?
You can assign a ResourceBundle with a logger. If you don't, it will inherit the ResourceBundle from its parent. The following example localizes a message based on the current locale. Comment out the first line and it will use the default locale (eg. en_US) and hence our ListResourceBundle MyLogResources. Notice that you can set MessageFormat parameters ({0}, {1}, ...) by using another form of the log method. Main.java:
MyLogResources.java:
MyLogResources_fr.java:
Running java Main outputs:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|