String msg = msgcat.get("EOpenFile", dir, file, ex);The localized message is typically in a .properties file, e.g.
throw new IOException(msg, ex);
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?
- when coding this, you would have to update .properties file in addition to the .java file you're working on
- 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".
- It's difficult to check that the right parameters are used in the right order ({0}, {1}) etc.
- 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.
- 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
No comments:
Post a Comment