I'm building a serverless node.js web app on AWS (using Serverless Framework) and trying to implement internationalization on the backend (API Gateway/Lambda/DynamoDB).
For front-end(React), I use redux to store the selected language and react-intl to switch multiple languages. For the backend, what's the best way to implement internationalization?
Here are two ways I can think of, but there must be better ones.
A. Translate on the backend (Get language from path parameter)
path: {language}/validate
validate.js
export function main(event, context, callback) {
const language = event.pathParameters.language;
const data = JSON.parse(event.body);
callback(null, validate(language, data));
}
This way, I need to pass the language as a function parameter to everywhere, which is not desirable.
B. Translate on front-end (i18n, react-intl)
backend hello.js response
{
id: "samplePage.message.hello",
defaultMessage: `Hello, ${name}`,
values: { name }
}
frontend hello.js
<FormattedMessage {...response} />
ja.json (translation file for i18n)
{
"samplePage.message.hello": "こんにちは、{name}。",
}
This way, it looks like everything works fine without any trouble, but am I missing anything?