javaangularjsspringinternationalizationangular-translate

Internationalization of api error messages on front end or back end?


My team is currently working on a web project where the front end uses json api provided by the back end. The technology that we use is Spring Boot and AngularJS. The api has the standard error format that looks like this:

{
    "errorCode": "1111",
    "message": "Error occurred: some error message",
    "developerMessage": "message for developer"
}

The error response can also contain optional list of field validation errors. The question is where should we do the translation of user error messages? Should the back end return already translated message based on request's locale or should the front end use the errorCode and it's i18n mechanism. We have i18n mechanisms both on back end (Spring i18n support) and front end (angular-translate).

What is the best practice? What are the pros and cons of each approach? Any advice is appreciated.


Solution

  • I would do it by localizing everything on the frontend. Backend would send ids which client apps then translate to localized text.

    Benefits:

    Drawbacks:

    To support multiple client apps you might need resx transformation during bundling step in your build. It will create resource files in the format required by the client so you can keep a single source of translations