0
votes

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?

1
@user234461 I know Stackoverflow is an English site, but why should I not ask a question about internationalization? Many companies in english native countries provide services in multiple languages, and they also need to think about internationalization.rhythm
Because AWS is baduser234461

1 Answers

3
votes

We do the same as you suggest in B)...basically we have our backend on AWS lambda and access data from dynamodb.

All our translation happens in the frontend. Only difference we use i18next (more specific react-i18next but makes no difference if this or react-intl -> just offers a little more backends, caching, language detection,... https://www.i18next.com/).

If you like to learn more or see it in action checkout https://locize.com (or directly try it at https://www.locize.io/ 14d free trial) while the app currently only is available in english all the texts comes in via xhr loading and get applied on runtime (i18n).

If interested in how we use serverless at locize.com see following slides from a speech we gave last year: https://blog.locize.com/2017-06-22-how-locize-leverages-serverless/

Last but not least...if you like to get most out of your ICU messages and validation, syntax highlighting and proper plural conversion and machine translation by not destroying the icu dsl during MT -> Just give our service a try...it comes with 14d free trial.