Internationalization of logging and error messages for the server side

This is how one would throw an internationalizable message:
String msg = msgcat.get("EOpenFile", dir, file, ex);
throw new IOException(msg, ex);
The localized message is typically in a .properties file, e.g.
EOpenFile=F1231: Could not open file {1} in directory {0}: {2}
Each language has its own .properties file. The  msgcat class is a utility class that loads the .properties file. Logging messages to a log file typically uses the same constructs.

Looks cool, right? So what's my gripe?
  1. when coding this, you would have to update .properties file in addition to the .java file you're working on
  2. It's easy to make a typo in the message identifier,  EOpenFile in the example above; there is no compile time checking for these "constants".
  3. It's difficult to check that the right parameters are used in the right order ({0}, {1}) etc.
  4. When reviewing the .java file, it's difficult to check that the error message is used in the right context and that the error message is meaningful in the context.
  5. When reviewing the .properties files, it's difficult to determine where these error messages are used (if at all!) -- you can only find out through a full text search
Isn't there a better way?
Comments:

Post a Comment:
Comments are closed for this entry.
About

fkieviet

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today