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.

# this comment will be interpreted as header comment

# the value can continue to the next line if the previous line ends with a backslash
welcome_message = Welcome back, \
we have missed you

# multi line comments belong to the next key value pair
# as long as they are not interrupted by a white line
visit_count = this is your {visit} visit to our site

! comments in .properties files can start with exclamation mark
hello_user = Hello {username}

escaped_newline = a newline can be escaped \n by using backslash n

charset.escaped.u=actually german\\: muss gr\\u00F6sser gleich {value} sein

double_quoted="Using double quotes"
single_quotes='Using single quotes"

References

 

 

 



Was this Helpful ?   yes     no Chat with us