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

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


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

Benefits:

  • single source of translation for everything - buttons, tooltips etc and the error messages
  • formatting support - you might need to make some parts of the message bold/clickable/etc which needs to be done on the frontend
  • client-only validation - error messages for client side validation should be the same as the server side ones for the same error (with backend localization you might end up duplicating some translations)
  • language agnostic testing is possible
  • language agnostic backend is possible - no need for locale on the backend just for the sake of translation
  • in sync with the general recommendation of localizing as close to the client as possible
  • removes the incentive of doing more backend translations in future

Drawbacks:

  • translation for new errors is not possible. If an error was defined on the backend after the client apps had been bundled, clients would need to display the generic message (but if necessary can display the new error id).
  • more complex bundling

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


If I had to do this, I would have done it on the back end, primarily because since the backend has the locale, and is also generating the errors, it does make sense to expect localized errors from it. It would also de-couple the systems, such that, if there is any new feature/change done on the back end, and a new error is added, you do not need to release the front end piece just for the error.

Also, once this scales up, and you have multiple backend systems, the above approach just works well, since all the error generators are responsible for taking care of their respective localizations.