Updating the message model

Next, we are going to update our message model. We are going to save the translated text, along with the language code to our message. This way, we can retrieve the translation for a given message and not hit the Translate API every time. Update server\models\message.ts as shown here:

// SNIPP SNIPPtranslations: {    type: Schema.Types.Mixed}// SNIPP SNIPP

Do note that this variable stores an object and not an array. The object will be built as follows:

// SNIPP SNIPP{ 'fr': 'Bonjour le monde!', 'en': 'Hello World!'}// SNIPP SNIPP

So, querying this variable will be easy given the language code.

Get Google Cloud AI Services Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.