Java Localization
Since JDK 1.1 Java uses the class java.util.ResourceBundle for internationalizing your Java applications. This implementation has slightly changed since then while being a proper implementation for this approach. On the other hand you will find abstractions for using this ResourceBundle base in your JSP, JSF … applications.
Format
Java uses the properties file format for storing your I18n key/value pairs. The properties standard is not really well-defined and various dialects exist. This article will focus on the Java dialect.
- Key-value pairs are delimited with the equal character (=), and terminated by a new line. The “=” may be surrounded by white spaces. (LingoHub does not support “:” as separator.)
- If the value shall continue in the next line, the line shall end with a backslash (\).
- Newlines can be escaped by using “\n”.
- A placeholder can have the following form: “{name}”, where name can consist of any number of non whitespace characters.
- Comment lines start with a hash sign (#) or an exclamation mark (!) and everything up to the end of line is treated as a comment.
- LingoHub will assign a comment to the next key-value pair. These comments will be used as translation descriptions and may include LingoChecks information.
- Java defines .properties files to be encoded in ISO-8859-1. Characters that are not included in this character set have to be masked by using so-called UTF-16 escaping (\u…. and \x..).
- However, Java also allows you to use UTF-8 encoded files. LingoHub recommends this approach as the files are easier to read for humans.
Example
Additional example files can be accessed here.