3

I found a million answers for how to add multi language support to a website/frontend. I can not find anyone talking about how to make the backend or API support multi language.

Simple example from my current project:

  • Nextjs React server for the frontend
  • Nodejs Express server on the backend exposing a GraphQL API
  • MongoDB connected to the backend server

So I know how to translate the frontend UI (e.g. button texts, paragraphs, headers, etc.) using the built in support from Nextjs. But how do I translate the information comming from the backend?

As an example I'll take the error messages returned by the API from the backend. Do I use a system so that the API knows which language the frontend requested and translate the error message on the backend? Do I send all data from the backend in english and translate on the frontend? Do I scrap any string data coming from the backend and just use codes, which need to be parsed to the right language on the frontend? If I use only codes, how can I have multi lingual data in my database?

I need information on what the standards or best practices are in a situation like this, where you have a full stack application that needs to deliver data in multiple languages.

Steve Melons
  • 83
  • 1
  • 7
  • 2
    I searched for i18n and found a NodeJS library for translations on the backend. https://www.npmjs.com/package/i18n. Internationalization and localization have been well studied and implemented for software. I would try to follow a system like i18n for your use case. As you can see in that library, the response will be based on which language code is provided and go to a certain path for the data. In their example it's a file, but it could be used to fetch data from the database that is saved specifically for that language. – Ben Bradshaw Jan 14 '21 at 20:49

0 Answers0