Translate Text to Different Languages using Amazon Translate- Part 1

May 13, 2022 | Comments(1) |


1. Introduction to Amazon Translate
2. Use Cases of Amazon Translate
3. Languages Supported by Amazon Translate
4. Steps and Code to Translate the Data
5. Lambda Code for Translating the Text and Storing the Translated files in S3
6. Final Code
7. Conclusion
8. About CloudThat
9. FAQs

1. Introduction to Amazon Translate

Translating text at a large scale is a massive challenge for many organizations that want to make themselves understood globally. Many organizations want their businesses to grow and try to make the text available in multiple languages so that everyone can understand it. Amazon Translate is the solution if we wish to translate the text for our website, provide localized text for our software applications, or provide a real-time translation. Amazon Translate accepts the text into one language and converts it to text in different languages. Amazon Translate helps to Translate the text in a fast, precise, and secure way.

Amazon Translate is a neural machine translation service that delivers fast, high-quality, affordable and customized language translation. Neural machine translation is a form of automated language translation that uses in-depth learning models to deliver more accurate and natural sound translations than standard math and rule-based translation algorithms.

With Amazon Translate, you can create local content such as websites and apps for various users, easily translate significant texts for analysis, and effectively enable interaction between users.

2. Use Cases of Amazon Translate:

Enhance multilingual customer experience using Amazon Translate:

  • Translate company-generated content such as meeting minutes, technical reports, articles, and publications.
  • Translate interpersonal communications such as email, in-game chat, and customer service chat so customers and employees can communicate in their preferred language.

Allow language-independent processing using Amazon Translate and other AWS services:

  • Extract named entities, sentiments, and key phrases from unstructured text such as social media feed using Amazon Comprehend.
  • Make subtitles and live captioning using Amazon Transcribe.
  • Convert translated content into Audio with Amazon Polly.
  • Translate document repositories stored in Amazon S3.
  • Easily integrate workflows with AWS Lambda or AWS Glue.

3. Languages Supported by Amazon Translate

Amazon Translate does not charge you for translations in which the source language and target language are the same.

Amazon Translate supports translation between the following 75 languages: Afrikaans, Albanian, Amharic, Arabic, Marathi, Norwegian, Farsi (Persian), Pashto, Polish, Portuguese, Portuguese (Portugal), Punjabi, Romanian, Russian, Serbian, Sinhala, Slovak, Slovenian, Somali, Spanish, Spanish (Mexico), Swahili, Swedish, Filipino Tagalog, Tamil, Telugu, Thai, Turkish, Ukrainian, Urdu, Uzbek, Vietnamese,  Armenian, Azerbaijani, Bengali, Bosnian, Bulgarian, Chinese (Simplified), Catalan, Chinese (Traditional), Croatian, Czech, Danish, Dari, Dutch, English, Estonian, Finnish, French, French (Canada), Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Irish, Italian, Japanese, Kannada, Kazakh, Korean, Latvian, Lithuanian, Macedonian, Malay, Malayalam, Maltese, Mongolian and Welsh.

4. Steps and Code to Translate the Data

This article will translate the data stored in a text file into different Languages. We will use S3 triggers that will make it possible to automate translation from start to end. Below is a detailed overview of what we will accomplish in this article.

  • Create a Lambda Role having access to the S3, Cloud Watch, and Amazon Translate service
  • Create an S3 bucket as an input and output bucket for Amazon
  • Create a Lambda function using python as a runtime to trigger Amazon Translate whenever a new .txt file is uploaded to the input S3 bucket.

Setting up a Trigger on S3

Click on the ‘Add Trigger’ option on the lambda, select ‘S3’ as a source, and select the Event Type as ‘PUT’. The prefix is the folder & suffix is the file type. We are considering only .txt files for the demo

Amazon Translate

5. Lambda Code for Translating the Text and Storing the Translated files in S3

  • Increase the Lambda timeout from Configuration Settings, By default, it is set to 3 secs.
  • Then we will import the required libraries like boto3 and unquote_plus.
  • We are using “unquote_plus” to replace escapes with their single-character equivalent
  • This code reads the Event and fetches the Bucket Name and File Name from the Event.
  • Then we use the “get_object” API to get the object. You can also use the “download_file” API to download the file as per your requirement
  • Then we are decoding the encoded data to get the actual File data
  • Here, we are considering the text to be in an “English” Language, If you want to detect the text automatically, so you can call ‘Amazon Comprehend’ service API to detect the text Language.
  • Now, we will Translate the “English” text into Different Languages like Hindi, Marathi, and Tamil.
  • There are 75 Languages supported by Amazon Translate, so you can make modifications in code as per your requirements
  • We are calling the “translate_text” API to Translate the text, We are supposed to give the source Language and the Target Language code.
  • Then we are creating a Text file and upload the file to S3. We are adding the Language Code to the File name for easy access to the Files.

6. Final Code

7. Conclusion

Now, if we upload a text file in our S3 bucket, our Lambda will be triggered and after execution of our lambda, we will be able to see a text file in our S3 bucket containing the text Translated from the Text File. This text can be used as per the business requirements for further processing depending on the use case.

In the next blog, we will be looking into Translating the SRT(SubRip Subtitle) files into different Languages using Amazon Translate. These SRT files are used to Provide the subtitles to the Video Files. Amazon Translate doesn’t support the SRT Files for Translation, So we will discuss the other approach to Translate the SRT files.

8. About CloudThat

CloudThat is also the official  Microsoft Gold Partner, AWS Advanced Consulting Partner, and Training partner helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding Amazon Translate, use cases, and any other AWS service, I will get back to you quickly. To get started, go through our Expert Advisory page and Managed Services Package that is CloudThat’s offerings.

9. FAQs

  1. What are the different inputs which Amazon Translate supports?

Ans. Amazon Translate supports plain text input in UTF-8 format.

  1. What are the size limits on the Translate API?

Ans. Amazon Translate API calls are limited to 5,000 bytes per API call. Amazon Translate, an asynchronous Batch Translation service, accepts a batch of up to 5 GB in size per API call

  1. Does Amazon Translate provide automatic source language detection?

Ans. Yes, Amazon Translate does automatic source language detection using Amazon Comprehend behind the scenes if the source language is unknown.

  1. Are requests where the source language and the target language are the same, charged?

Ans. No, Requests are not charged if the source language equals the target language.

One Response to “Translate Text to Different Languages using Amazon Translate- Part 1”

Leave a Reply