Overcome i18n empty string error message

The problem:
If you are using an i18n supported system like spring (java), there might be a scenario where your application might call an empty string.
This might occur when you invoke the i18n with a null or an empty string (i.e. the i18n key was not set correctly and the jsp i18n tag could not find it).
Then, when trying to translate the message using your i18n messages.properties file, the server might throw an exception.

That exception might be disruptive in a production environment.
In order to throw a silent exception, I took the approach of null vs. empty object handling.
(i.e. prefer returning an empty object rater than null, when an error occurs).

The solution:
To avoid this exception, you can add an entry for an empty string to your i18n messages.properties like so:

conf.btn.submit = SUBMIT
conf.status.none = NONE
conf.status.deleted = DELETED
conf.status.inactive = INACTIVE
= i18n empty string error
conf.status.active = ACTIVE
conf.status.incomplete = INCOMPLETE
conf.status.pending = PENDING
conf.status.approved = APPROVED
conf.status.rejected = REJECTED

Ofcourse, you might want to use some other text than "error" according to the specific need of your application. Displaying "Error" is a way of floating up the problem without displaying the user/QA a blank screen.

Note:
This technique could also be used in development to focus on business logic development, however, I would recommend DELETING this empty i18n key during the last test days, before going to production, to minimize such exceptions.

No comments: