Search |
|||||||||||||||||||
The backslash of ResourceBundlePosted by felipegaucho on July 16, 2007 at 1:48 AM PDT
Few days ago I received a simple Java task: to take a comma-separated values (CSV) file and to create a Properties file for every column. The content of CSV file was delimited by semicolon; and the data was typed as the example below. Notice that first token of each line in the csv file represents a key and the other tokens should be split in different files - one for each language.
To solve this problem, I decided to create an ANT task with the following algorithm:
Quite simple, and it worked since the very first time I run it. But when I checked the generated files, I got a surprise: the generated file included some unexpected backslashes before some characters. Checking the API documentation, I got other surprises about the store(..) method:
The escape sequence rendering is well documented since Java 1.2, then I assume it was my fault not to know about that, but wait: I am developing software in Java for more than ten years now, and I really don't remember i18n files generated with backslashes - so I decided to ask about that in mailing lists. My suspicious was confirmed, almost nobody really knows about these minor tricks in internationalization Properties. Going deep in the code of Java I figured out the reason of this unconsciousness: the method getBundle(String baseName) of the class ResourceBundle supports special characters with or without the backslash, and since the most part of i18n files are created by hand, we never remember the minor details. From my original example, we have the following output:
Interesting, a good reason to check the javadoc sometimes :) »
Related Topics >>
Programming Comments
Comments are listed in date ascending order (oldest first)
|
|||||||||||||||||||
|
|