How to translate chat messages in different languages in real time with Amazon Translate?

Reading Time: 10 minutes
How to translate chat messages in different languages in real time with Amazon Translate?

We are in the age of globalization! Nowadays many businesses are expanding their reach to wider audiences across the globe, which made the world a global village! Businesses across the globe require applications that are interoperable with multiple languages. So businesses have a need for scalable, reliable, and cost-effective solutions to create multilanguage-supported applications. 

Traditional methods included statistical and rule-based translation models. conventional phrase-based machine translation which used to only translate within the context of a few words before and after the translated word. Amazon Translate is a neural machine translation service that delivers fast, high-quality, and affordable language translation. Amazon Translate enables you to meet this challenge by delivering accurate natural-sounding translations using a cloud-based deep learning API.

Let’s Explore!

In this blog, we will cover:

  • What is neural machine translation?
  • What is Amazon Translate?
  • Amazon Translate features.
  • How does Amazon Translate work?
  • Benefits of Amazon Translate
  • Use cases of Amazon Translate
  • Why should you use Amazon Translate?
  • Amazon Translate Pricing
  • Companies using Amazon Translate
  • Hands-On 
  • Conclusion

What are Neural machine translations?

Neural Machine Translation (NMT) is an end-to-end learning approach for automated translation from one language to another. It uses deep learning models to deliver more accurate and more natural-sounding translations than traditional statistical and rule-based translation algorithms.

What is Amazon Translate?

Amazon Translate is the AI/ML service provided by AWS. It relies upon neural machine translation engines using a collection of evolving datasets that provide the basis for Amazon Translate’s continuous learning and ability to provide increasingly accurate translations.

Intento recently ranked Amazon Translate as the top machine translation provider in 2020 across 14 language pairs, 16 industry sectors, and 8 content types

Amazon Translate Features 

How to translate chat messages in different languages in real time with Amazon Translate?

How does Amazon Translate work ?

The translation model has two components, the encoder, and the decoder. Theencoder reads a source sentence one word at a time and constructs a semantic representation that captures its meaning. The decoder uses the semantic representation to generate a translation one word at a time in the target language.

When working with Amazon Translate, you will provide source text and get output text:

  • Source text: The text that you want to translate.
  • Output text: The text that Amazon Translate has translated into the target language. Depending on the source and target languages, there might be more characters in the output text than in the input text.

Benefits of Amazon Translate

Customizable: Amazon Translate lets you customize your machine-translated output, with Custom Terminology and Active Custom Translation. You don’t need to build a custom translation model, you can update your model as often as you need! The best part is you only pay for the number of characters you translate!

Scalable: Amazon Translate easily scales to meet large volumes of translation needs with fast and reliable translations.

Highly Accurate and continuously Improving: The translation engines are always improving from new and expanded datasets. It means you can get more accurate translations for a wide range of use cases.

Versatile: Amazon Translate has the ability to translate various content formats including Word documents, Powerpoint presentations, and Excel spreadsheets, etc.

How to translate chat messages in different languages in real time with Amazon Translate?

Easy to Integrate into any application – In today’s global world, there is a need for multilingual data-based applications. You can integrate Amazon Translate to localize an application or website, or process multilingual data. It has the ability to process a real-time high volume of data with a simple API call.

Use cases of Amazon Translate

Communication: Amazon Translate can provide cross-lingual communications between users for your application’s automatic translation. By adding real-time translation to chat, email, helpdesk, and ticketing applications.

Language localization: Easily translates massive volumes of user-generated content in real-time. Websites and applications can automatically make content such as feed stories, profile descriptions, and comments, available in the user’s preferred language by clicking on a “translate” button.

How to translate chat messages in different languages in real time with Amazon Translate?

Text Analytics: It translates the text to English before using a natural language processing (NLP) application to analyze textual content in a multitude of languages.

Why should you use Amazon Translate?

Amazon Translate expands your customers’ reach and enables communication with them more effectively. Many businesses have large volumes of content, user or company authored; the only way to make all of it accessible in multiple languages in a timely manner is to use Machine Translation. 

Amazon Translate supports business growth and expansion. With Amazon Translate, LSPs can increase productivity by as much as 50% and produce larger volumes of translation. Amazon Translate also allows you to customize your translation output using Active Custom Translation, as LSPs, you protect your IP when you use ACT to provide a customized translation.

Amazon Translate Pricing

Companies using Amazon Translate 

Hands-On

In this hands on, we will see how we can configure Amazon Translate, attach an IAM policy to an IAM user for the permissions to perform the translation, and finally build a  React chat application where users can select their preferred language, and have messages sent to them translated to that language in real-time using Amazon Translate. 

To follow and use the same code shown in this blog can clone the following repository:

https://github.com/workfall/AWS-Translate

How to translate chat messages in different languages in real time with Amazon Translate?

To implement this, we will do the following:

  • Sign in to your AWS console and navigate to the IAM dashboard.
  • Create a new user with Programmatic access and attach a translated full access policy to the newly created user.
  • Note down the Access key and Secret Key.
  • Navigate to ‘getstream.io’ and signup with email or with GitHub.
  • Enable the chat UI to be authorised to use the UI in your application.
  • Navigate to the dashboard and create a new app.
  • Note down the API Key and Secret Key.
  • Set up the Server and run the server.
  • Set up the React application and run the application.
  • Build the Chat UI.
  • Test out the translations performed for a real time chat room.

Login to your AWS console and navigate to the Amazon IAM Dashboard. Click on ‘Add user’.

How to translate chat messages in different languages in real time with Amazon Translate?

Enter a ‘user name’ and select the Access type as ‘Programmatic access’. Once done, click on ‘Next: Permissions’.

In the search box, enter ‘translate’, check the checkbox for the ‘TranslateFullAccess’ policy and click on ‘Next: Tags’.

How to translate chat messages in different languages in real time with Amazon Translate?

Enter tags (if any) for the new user you are creating and click on ‘Next: Review’.

Review the details you filled in along with reviewing the policy you attached and click on ‘Create user’.

How to translate chat messages in different languages in real time with Amazon Translate?

Once the user has been created, click on ‘Download .csv’ to store a copy of the ‘Access key ID’ and ‘Secret access key’ of the created user.

Now, click on the below link to create a new Stream account. 

https://getstream.io/accounts/signup/

You will be directed to a page as shown below. You can either sign up by filling in the details or you can sign up with GitHub. In this blog, we will be signing up with GitHub. Click on ‘Sign up with GitHub’.

How to translate chat messages in different languages in real time with Amazon Translate?

Click on ‘Authorize GetStream’ to complete the sign-up process.

How to translate chat messages in different languages in real time with Amazon Translate?

On success, you will be navigated to a page as shown below.

Hover on the ‘Chat Messaging’ on the top of the screen and click on ‘Try For Free’.

How to translate chat messages in different languages in real time with Amazon Translate?

You will see the various chat UI’s available. You can select one based on your preference. In this blog, we will be selecting the ‘Social Messenger’ chat UI. In the bottom left navigation pane, click on ‘Start for Free’ to proceed. 

On the second half of the page, you will see a button ‘Get started with the free trial’. Click on it and once you refresh the page, you will see the below message. Now, click on ‘Dashboard’ to create a new app.

Once you’re redirected to the dashboard, you will see the organization based on what you entered while signing up. A production app will be automatically created when you navigate to the dashboard. Now let’s create a development app.

Click on ‘Create App’.

A modal will appear. Enter an app name for your application, select the server location from the dropdown, under Environment, select ‘Development’ and once done, click on ‘Create App’.

You will be navigated to the newly created app’s dashboard. Scroll down to the bottom and note down the ‘Key’ and ‘Secret’ since we will be needing it while configuring the application.

How to translate chat messages in different languages in real time with Amazon Translate?

Set Up the Server

Create a new directory for this project in your filesystem and cd into it. Following that, run the command below to install all the dependencies that are needed to build the server:

yarn add express dotenv cors aws-sdk stream-chat body-parser

Once the installation starts, you will see something like shown below on your command prompt. This command installs:

express: Node.js web application framework

dotenv: For loading environmental variables from a .env file into process.env

cors: Node.js CORS middleware

aws-sdk: The official AWS SDK for the browser and Node.js

stream-chat: The Stream chat library

body-parser: Node.js body parsing middleware

Next, create a new ‘.env’ file in the project root and add the following environmental variables to it, replacing the placeholders with the appropriate values from your Stream and AWS IAM dashboards:

How to translate chat messages in different languages in real time with Amazon Translate?

Save the ‘.env’ file, then go ahead and create a new server.js file in the project root. Open it in your text editor, and add in the following code:

How to translate chat messages in different languages in real time with Amazon Translate?

You can start the server on port 5500. Navigate back to your command prompt and run the below command to start the server.

Node server.js

On success, you will see a message as shown below on your command prompt.

Set Up the React Application

Within your project directory, install the create-react-app using the below command:

npm install create-react-app

Now, use the create-react-app CLI to bootstrap a new React application using the command below.

npx create-react-app client

When you execute the below command, you will see something like shown below:

Once the app has been created, cd into the new client directory and install the following additional dependencies using the command below:

yarn add stream-chat stream-chat-react random-username-generator axios

On executing the command, you will see something like as shown below.

How to translate chat messages in different languages in real time with Amazon Translate?

Once the installation is complete, start your development server by running the command ‘npm start’ or ‘yarn start’ from within the client directory. On successful compilation, you see something like as shown in the image below on your command prompt:

Now you can navigate to http://localhost:3000 in your browser to view the newly created app.

Build the Chat UI

Open up client/src/App.js in your text editor and update it to look like the snippet below:

How to translate chat messages in different languages in real time with Amazon Translate?

Now, navigate back to your browser and load the application. You will see a UI screen as shown below. Click on the dropdown on the rightmost top of the UI screen.

You will see the different languages in which you can perform the translation of messages as shown below. The different members you see under the Discussion header are created by the stream application itself. 

Navigate back to the stream dashboard and click on ‘Options’ and select ‘Open in Chat Explorer’.

Now select users and you will see the list of all the users created by the stream application.

On selecting a specific user, you will see the details of that user as shown below.

Now to test the translation, open the same application in 2 different tabs in the browser. You will see the online users count increases. Now on one of the chat screens, select some other language and test out the real time translation.

Send a text from one screen and you will see the translated results on the other screen and vice versa.

In this, the language is selected as Spanish on the right screen so the translation happening is English to Spanish and Spanish to English.

In this, the language is selected as French on the right screen so the translation happening for the remaining texts is from English to French and from French to English.

How to translate chat messages in different languages in real time with Amazon Translate?

Conclusion

In this blog, we have implemented a solution on how to translate text between languages using Amazon Translate. Amazon Translate enables you to meet this challenge by delivering accurate natural-sounding translation using a cloud-based deep learning API. You can explore this feature using Amazon Translate Free Tier! Translate up to 2M characters monthly – free for the first 12 months, starting from your first translation request.

We will discuss more advanced topics of AWS services in our upcoming blogs. Stay tuned to keep getting all updates about our upcoming new blogs on AWS and relevant technologies.

Meanwhile …

Keep Exploring -> Keep Learning -> Keep Mastering

This blog is part of our effort towards building a knowledgeable and kick-ass tech community. At Workfall, we strive to provide the best tech and pay opportunities to AWS-certified talents. If you’re looking to work with global clients, build kick-ass products while making big bucks doing so, give it a shot at workfall.com/partner today.

Back To Top