ML 12715 Picture2
A critical component of business success is the ability to connect with customers. Businesses today want to connect with their customers by offering their content across multiple languages in real time. For most customers, the content creation process is disconnected from the localization effort of translating content into multiple target languages. These disconnected processes delay the business ability to simultaneously publish content in multiple languages, inhibiting their outreach efforts which negatively impacts time to market and revenue.
Amazon Translate is a neural machine translation service that delivers fast, high-quality, and affordable language translation. Now, Amazon Translate offers real-time document translation to seamlessly integrate and accelerate content creation and localization. You can submit a document from the AWS Management Console, AWS Command Line Interface (AWS CLI), or AWS SDK and receive the translated document in real time while maintaining the format of the original document. This feature eliminates the wait for documents to be translated in asynchronous batch mode.
Real-time document translation currently supports plain text and HTML documents. You can use other Amazon Translate features such as custom terminology, profanity masking, and formality as part of the real-time document translation.
In this post, we will show you how to use this new feature.
This post walks you through the steps required to use real-time document translation with the console, AWS CLI, and Amazon Translate SDK. As an example, we will translate this sample text file from English to French.
Follow these steps to try out real-time document translation on the console:
Note: Source or Target language should be English for real-time document translation.
Text and HTML formats are supported at the time of this writing.
For more information about Amazon Translate features, refer to the following resources:
The translated file is automatically saved to your browser’s downloaded folder, usually to Downloads. The target language code will be prefixed to the translated file’s name. For example, if your source file name is lang.txt
and your target language is French (fr
), then the translated file will be named fr.lang.txt
.
You can translate the contents of a file using the following AWS CLI command. In this example, the contents of source-lang.txt
will be translated into target-lang.txt.
aws translate translate-document --source-language-code en --target-language es
--document-content fileb://source-lang.txt
--document ContentType=text/plain
--query "TranslatedDocument.Content"
--output text | base64
--decode > target-lang.txt
You can use the following Python code to invoke Amazon Translate SDK API to translate text or HTML documents synchronously:
import boto3
import argparse
# Initialize parser
parser = argparse.ArgumentParser()
parser.add_argument("SourceLanguageCode")
parser.add_argument("TargetLanguageCode")
parser.add_argument("SourceFile")
args = parser.parse_args()
translate = boto3.client('translate’)
localFile = args.SourceFile
file = open(localFile, "rb")
data = file.read()
file.close()
result = translate.translate_document(
Document={
"Content": data,
"ContentType": "text/html"
},
SourceLanguageCode=args.SourceLanguageCode,
TargetLanguageCode=args.TargetLanguageCode
)
if "TranslatedDocument" in result:
fileName = localFile.split("/")[-1]
tmpfile = f"{args.TargetLanguageCode}-{fileName}"
with open(tmpfile, 'w', encoding='utf-8') as f:
f.write(str(result["TranslatedDocument"]["Content"]))
print("Translated document ", tmpfile)
This program accepts three arguments: source language, target language, and file path. Use the following command to invoke this program:
python syncDocumentTranslation.py en es source-lang.txt
The real-time document translation feature in Amazon Translate can expedite time to market by enabling easy integration with content creation and localization. Real-time document translation improves content creation and the localization process.
For more information about Amazon Translate, visit Amazon Translate resources to find video resources and blog posts, and refer to AWS Translate FAQs.
One of the significant challenges statisticians and data scientists face is multicollinearity, particularly its most…
Artificial intelligence is not just altering the way we interact with technology; it’s reshaping the…
This post was co-written with Mickey Alon from Vidmob. Generative artificial intelligence (AI) can be…
Prompt Poet allows you to ground LLM-generated responses to a real-world data context, opening up…
NASA has three more operational Starliner missions on the books. It hasn't decided whether it…
When training a machine learning model, you may sometimes work with datasets with a large…