Error Message Localisation

Problem Definition:

All the error messages coming from the platform should be localised based on the configured language.

Key area to be analysed:

  • Error Code Naming convention
  • How to be called from different module
  • How to segregate different code

Error Code Naming convention:

  • Currently there is no particular naming convention, and the developer creates Error code as per there convention.
  • There are multiple codes which are having same meaning.
  • There should be a specific pattern to generate error code so that the redundancy of error code can be achieved.
  • Proposed Pattern:

    Response Code: ERR
    Object Type: Object Type in capital case (Ex: CONTENT/FRAMEWORK)
    API/Operation code: Called API/Operation code
    Actual Code:

  • eg: ERR_CONTENT_UPDATE_RESOURCE_NOT_FOUND
  • Each module will have enum for actual error code. Based on error code data will be fetched from resource bundle and custom error code will be returned back with message.
  • There can be some generic error code like CACHE_ERROR, CONNECTION_PROBLEM which will not need any custom naming conventions.


How to be called from different module:

  • The error code can be passed from different module, therefor Error code Api should be available in different module which can be added as dependency.
  • Each module will be having enum for error codes and there respective value will be fetched from property files based on configuration.

How to segregate different code:

  • Need more analysis.


Below are few implement for internationalised error messaging system:

1. Java Resource Bundle
2. cal10n (few benefits are there, like - use Enum, testing the duplicity is simple through unit test)
3. spring Resource Bundle (ResourceBundleMessageSource)
4. resource4j (not very much clear idea, but did poc)


Java Resource Bundle:

  • Java provides ResouceBundle library.
  • No additional library required.

cal10n:

  • Add dependency of cal10n-api
  • Each module can have Error Enum
  • Unit testing for duplicate key or missing key is easy
  • Default implementation is easy

spring Resource Bundle:

  • Add spring dependencies.
  • ResourceBundleMessageSource can be used to resolve text messages from properties file.
  • All the properties files are consider to be one.