• 沒有找到結果。

Amazon Translate

N/A
N/A
Protected

Academic year: 2022

Share "Amazon Translate"

Copied!
182
0
0

加載中.... (立即查看全文)

全文

(1)

Amazon Translate

Developer Guide

(2)

Amazon Translate: Developer Guide

Copyright © Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.

(3)

Table of Contents

What Is Amazon Translate? ... 1

Supported Languages and Language Codes ... 1

Limitations in Language Support ... 3

Use Cases ... 4

First-Time User ... 4

Amazon Translate Pricing ... 4

How It Works ... 5

Automatic Language Detection ... 5

Exception Handling ... 5

Next Steps ... 6

Getting Started ... 7

Step 1: Set Up an Account ... 7

Sign Up for AWS ... 7

Create an IAM User ... 7

Next Step ... 8

Step 2: Set Up the AWS CLI ... 8

Next Step ... 9

Step 3: Getting Started (Console) ... 9

Next Step ... 10

Step 4: Getting Started (AWS CLI) ... 10

Translate Text Using the Command Line ... 11

Translate Text Using a JSON File ... 11

Next Step ... 12

Step 5: Getting Started (SDK) ... 12

Using the SDK for Java ... 12

Using the AWS SDK for Python ... 13

Using the Mobile SDK for Android ... 15

Using the Mobile SDK for iOS ... 16

Translation Processing Modes ... 18

Real-Time Translation ... 18

Asynchronous Batch Processing ... 18

Region Availability ... 18

Prerequisites ... 19

Running a Job ... 22

Monitoring and Analyzing ... 26

Getting Results ... 27

Customizing Your Translations ... 29

Masking Profanity ... 29

Using the Profanity Setting ... 29

Unsupported Languages ... 30

Setting Formality ... 30

Using the Formality Setting ... 31

Supported Languages ... 31

Customizing with Custom Terminology ... 31

How does this work? ... 32

Creating a Custom Terminology ... 32

Using Custom Terminologies ... 34

Encrypting Your Terminology ... 35

Best Practices ... 35

Customizing with Parallel Data ... 36

Region Availability ... 37

Parallel Data Input Files for Amazon Translate ... 37

Adding Parallel Data ... 41

Viewing and Managing Parallel Data ... 43

(4)

Examples ... 47

Using Amazon Polly with Amazon Translate ... 47

Code ... 47

Using Amazon Translate to Translate a Chat Channel ... 51

Using Amazon Translate with DynamoDB ... 59

Example Code ... 60

Using Amazon Translate to Translate a Web Page ... 62

Using Amazon Translate to Translate Large Documents ... 65

Using Signature Version 4 with Amazon Translate ... 67

Setting Up ... 67

Code ... 67

Security ... 71

Data Protection ... 71

Encryption at Rest ... 72

Encryption in Transit ... 73

Identity and Access Management ... 73

Audience ... 73

Authenticating With Identities ... 74

Managing Access Using Policies ... 75

Allow Users to View Their Own Permissions ... 77

How Amazon Translate Works with IAM ... 78

Identity-Based Policy Examples ... 80

Troubleshooting ... 82

Amazon Translate API Permissions Reference ... 84

Monitoring ... 84

Monitoring with CloudWatch ... 86

Logging Amazon Translate API Calls with AWS CloudTrail ... 87

CloudWatch Metrics and Dimensions for Amazon Translate ... 89

Monitoring with EventBridge ... 91

Compliance Validation ... 93

Resilience ... 93

Infrastructure Security ... 93

VPC endpoints (AWS PrivateLink) ... 94

Considerations for Amazon Translate VPC endpoints ... 94

Creating an interface VPC endpoint for Amazon Translate ... 94

Creating a VPC endpoint policy for Amazon Translate ... 94

Guidelines and Limits ... 96

Supported AWS Regions ... 96

Compliance ... 96

Throttling ... 96

Guidelines ... 96

Service Limits ... 96

Document History ... 99

API Reference ... 105

HTTP Headers ... 105

Actions ... 105

CreateParallelData ... 107

DeleteParallelData ... 110

DeleteTerminology ... 112

DescribeTextTranslationJob ... 114

GetParallelData ... 117

GetTerminology ... 120

ImportTerminology ... 123

ListParallelData ... 126

ListTerminologies ... 129

ListTextTranslationJobs ... 132

StartTextTranslationJob ... 135

(5)

StopTextTranslationJob ... 140

TranslateText ... 142

UpdateParallelData ... 146

Data Types ... 149

AppliedTerminology ... 150

EncryptionKey ... 151

InputDataConfig ... 152

JobDetails ... 154

OutputDataConfig ... 155

ParallelDataConfig ... 156

ParallelDataDataLocation ... 157

ParallelDataProperties ... 158

Term ... 161

TerminologyData ... 162

TerminologyDataLocation ... 164

TerminologyProperties ... 165

TextTranslationJobFilter ... 168

TextTranslationJobProperties ... 169

TranslationSettings ... 172

Common Errors ... 172

Common Parameters ... 174

AWS glossary ... 177

(6)

Supported Languages and Language Codes

What Is Amazon Translate?

Amazon Translate is a text translation service that uses advanced machine learning technologies to provide high-quality translation on demand. You can use Amazon Translate to translate unstructured text documents or to build applications that work in multiple languages.

Supported Languages and Language Codes

Amazon Translate provides translation between a source language (the input language) and a target language (the output language). A source language-target language combination is known as a language pair.

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

Amazon Translate can translate text between the languages listed in the following table.

Language Language Code

Afrikaans af

Albanian sq

Amharic am

Arabic ar

Armenian hy

Azerbaijani az

Bengali bn

Bosnian bs

Bulgarian bg

Catalan ca

Chinese (Simplified) zh

Chinese (Traditional) zh-TW

Croatian hr

Czech cs

Danish da

Dari fa-AF

Dutch nl

English en

Estonian et

(7)

Supported Languages and Language Codes

Language Language Code

Farsi (Persian) fa

Filipino, Tagalog tl

Finnish fi

French fr

French (Canada) fr-CA

Georgian ka

German de

Greek el

Gujarati gu

Haitian Creole ht

Hausa ha

Hebrew he

Hindi hi

Hungarian hu

Icelandic is

Indonesian id

Irish ga

Italian it

Japanese ja

Kannada kn

Kazakh kk

Korean ko

Latvian lv

Lithuanian lt

Macedonian mk

Malay ms

Malayalam ml

Maltese mt

Marathi mr

Mongolian mn

Norwegian no

(8)

Limitations in Language Support

Language Language Code

Pashto ps

Polish pl

Portuguese pt

Portuguese (Portugal) pt-PT

Punjabi pa

Romanian ro

Russian ru

Serbian sr

Sinhala si

Slovak sk

Slovenian sl

Somali so

Spanish es

Spanish (Mexico) es-MX

Swahili sw

Swedish sv

Tamil ta

Telugu te

Thai th

Turkish tr

Ukrainian uk

Urdu ur

Uzbek uz

Vietnamese vi

Welsh cy

Limitations in Language Support

The following features in Amazon Translate have limitations in the languages that they support.

• Profanity masking – For the languages supported by this feature, see Masking Profane Words and Phrases in Amazon Translate (p. 29).

• Formality – For the languages supported by this feature, see Setting Formality in Amazon Translate (p. 30).

(9)

Use Cases

Use Cases

Use Amazon Translate to do the following:

Enable multilingual user experiences in your applications by integrating Amazon Translate:

• Translate company-authored content, such as meeting minutes, technician reports, knowledge- base articles, posts, and more.

• Translate interpersonal communications, such as email, in-game chat, customer service chat, so that customers and employees can connect in their preferred language.

Process and manage your company's incoming data:

• Analyze text, such as social media and news feeds, in many languages.

• Search for information, such as for eDiscovery cases, in many languages.

Enable language-independent processing by integrating Amazon Translate with other AWS services:

• Extract named entities, sentiment, and key phrases from unstructured text, such as social media streams with Amazon Comprehend.

• Make subtitles and live captioning available in many languages with Amazon Transcribe.

• Speak translated content with Amazon Polly.

• Translate document repositories stored in Amazon S3 .

• Translate text stored in the following databases: Amazon DynamoDB, Amazon Aurora, and Amazon Redshift.

• Seamlessly integrate workflows with AWS Lambda or AWS Glue.

Are You a First-time User of Amazon Translate?

If you are a first-time user, we recommend that you read the following sections in order:

1.How Amazon Translate Works (p. 5) – Introduces Amazon Translate.

2.Getting Started with Amazon Translate (p. 7) – Explains how to set up your AWS account and start using Amazon Translate.

3.Examples (p. 47) – Provides code examples in Java and Python. Use the examples to explore how Amazon Translate works.

4.API Reference (p. 105) – Contains reference documentation for Amazon Translate operations.

Amazon Translate Pricing

As with other AWS products, there are no contracts or minimum commitments for using Amazon

Translate. For more information about the cost of using Amazon Translate, see Amazon Translate Pricing.

(10)

Automatic Language Detection

How Amazon Translate Works

The Amazon Translate service is based on neural networks trained for language translation. This enables you to translate between a source language (the original language of the text being translated) and a target language (the language into which the text is being translated). For more information, see Supported Languages and Language Codes (p. 1).

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

Source text—The text that you want to translate. You provide the source text in UTF-8 format.

Output text—The text that Amazon Translate has translated into the target language. Output text is also in UTF-8 format. Depending on the source and target languages, there might be more characters in the output text than in the input text.

The translation model has two components, the encoder and the decoder. The encoder 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.

Amazon Translate uses attention mechanisms to understand context. This helps it decide which words in the source text are most relevant for generating the next target word. Attention mechanisms enable the decoder to focus on the most relevant parts of a source sentence. This ensures that the decoder correctly translates ambiguous words or phrases.

The target word that the model generates becomes input to the decoder. The network continues generating words until it reaches the end of the sentence.

Automatic Language Detection

Amazon Translate can automatically detect the language used in your source text. To use automatic language detection, specify auto as the source language. Amazon Translate calls Amazon Comprehend on your behalf to determine the language used in the source text. By choosing automatic language detection, you agree to the service terms and agreements for Amazon Comprehend. For information about pricing for Amazon Comprehend, see Amazon Comprehend Pricing.

Exception Handling

If you specify a source or target language that isn't supported, Amazon Translate returns the following exceptions:

UnsupportedLanguagePairException – Amazon Translate supports translation between all supported languages. This exception is returned if either the source language or target language is unsupported.

For more information, see Supported Languages (p. 1).

DetectedLanguageLowConfidenceException – If you use automatic language detection, and Amazon Translate has low confidence that it detected the correct source language, it returns this exception. If a low confidence level is acceptable, you can use the source language returned in the exception.

(11)

Next Steps

Next Steps

Now that you've learned how Amazon Translate works, you can explore the following sections to learn about creating a solution.

• Getting Started with Amazon Translate (p. 7)

• Examples (p. 47)

(12)

Step 1: Set Up an Account

Getting Started with Amazon Translate

To get started using Amazon Translate, set up an AWS account and create an AWS Identity and Access Management (IAM) user. To use the AWS Command Line Interface (AWS CLI), download and configure it.

Topics

• Step 1: Set Up an AWS Account and Create an Administrator User (p. 7)

• Step 2: Set Up the AWS Command Line Interface (AWS CLI) (p. 8)

• Step 3: Getting Started (Console) (p. 9)

• Step 4: Getting Started (AWS CLI) (p. 10)

• Step 5: Getting Started (SDK) (p. 12)

Step 1: Set Up an AWS Account and Create an Administrator User

Before you use Amazon Translate for the first time, complete the following tasks:

1.Sign Up for AWS (p. 7) 2.Create an IAM User (p. 7)

Sign Up for AWS

When you sign up for Amazon Web Services (AWS), your AWS account is automatically signed up for all AWS services, including Amazon Translate. You are charged only for the services that you use.

With Amazon Translate, you pay only for the resources that you use. If you are a new AWS customer, you can get started with Amazon Translate for free. For more information, see AWS Free Usage Tier.

If you already have an AWS account, skip to the next section.

To create an AWS account

1. Open https://portal.aws.amazon.com/billing/signup.

2. Follow the online instructions.

Part of the sign-up procedure involves receiving a phone call and entering a verification code on the phone keypad.

Record your AWS account ID because you'll need it for the next task.

Create an IAM User

AWS services, such as Amazon Translate, require that you provide credentials when you access them. This allows the service to determine whether you have permissions to access the service's resources.

(13)

Next Step

We strongly recommend that you access AWS using AWS Identity and Access Management (IAM), not the credentials for your AWS account. To use IAM to access AWS, create an IAM user, add the user to an IAM group with administrative permissions, and then grant administrative permissions to the IAM user. You can then access AWS using a special URL and the IAM user's credentials.

Exercises in this guide assume that you have an IAM user with administrator privileges called adminuser.

To create an administrator user

• In your AWS account, create an administrator user called adminuser. For instructions, see Creating Your First IAM User and Administrators Group in the IAM User Guide.

For more information about IAM, see the following:

• AWS Identity and Access Management (IAM)

• Getting started

• IAM User Guide

Next Step

Step 2: Set Up the AWS Command Line Interface (AWS CLI) (p. 8)

Step 2: Set Up the AWS Command Line Interface (AWS CLI)

You use the AWS CLI to make interactive calls to Amazon Translate.

To set up the AWS CLI

1. Download and configure the AWS CLI. For instructions, see the following topics in the AWS Command Line Interface User Guide:

• Getting Set Up with the AWS Command Line Interface

• Configuring the AWS Command Line Interface

2. In the AWS CLI config file, add a named profile for the administrator user:

[profile adminuser]

aws_access_key_id = adminuser access key ID

aws_secret_access_key = adminuser secret access key region = aws-region

You use this profile when executing AWS CLI commands. For more information about named profiles, see Named Profiles in the AWS Command Line Interface User Guide. For a list of AWS Regions, see Regions and Endpoints in the Amazon Web Services General Reference.

3. Verify the setup by typing the following help command at the command prompt:

aws translate help

You should see a brief description of Amazon Translate and a list of the available commands.

(14)

Next Step

Next Step

Step 3: Getting Started (Console) (p. 9)

Step 3: Getting Started (Console)

The easiest way to get started with Amazon Translate is to use the console to translate some text.

You can translate up to 5,000 characters using the console. If you haven't reviewed the concepts and terminology in How Amazon Translate Works (p. 5), we recommend that you do so before proceeding.

To start translating text, go to the AWS Management Console and open the Amazon Translate console.

If this is the first time that you've used Amazon Translate, choose Launch real-time translation.

In Real-time translation, choose the source and target languages. Enter the text that you want to translate in the left-hand text box. The translated text appears in the right-hand text box.

In the JSON samples section you can see the JSON input and output to the TranslateText (p. 142) operation.

(15)

Next Step

Next Step

Step 4: Getting Started (AWS CLI) (p. 10)

Step 4: Getting Started (AWS CLI)

In the following exercises, you use the AWS command line interface (AWS CLI) to translate text.

To complete these exercises, you need to be familiar with the CLI and have a text editor. For more information, see Step 2: Set Up the AWS Command Line Interface (AWS CLI) (p. 8).

There are two ways to use the CLI to translate text with Amazon Translate. For short text, you can provide the text that you want to translate as a parameter of the translate-text command. For longer text, you can provide the source language, target language, and text in a JSON file.

To use Amazon Translate from the command line, you need to know the endpoint and region for the service. For a list of available endpoints and regions, see Amazon Translate Regions and Endpoints in the AWS General Reference.

(16)

Translate Text Using the Command Line

Translate Text Using the Command Line

The following example shows how to use the translate-text operation from the command line to translate text. The example is formatted for Unix, Linux, and macOS. For Windows, replace the backslash (\) Unix continuation character at the end of each line with a caret (^). At the command line, type the following.

aws translate translate-text \ --region region \

--source-language-code "en" \ --target-language-code "es" \ --text "hello, world"

The response is the following JSON:

{ "TargetLanguageCode": "es", "Text": "Hola, mundo", "SourceLanguageCode": "en"

}

Translate Text Using a JSON File

This example shows how to use the translate-text operation to translate a longer text block from a JSON file. You can specify the source and target language on the command line, but in this example, you specify them in the JSON file.

NoteThe JSON file is formatted for readability. Reformat the "Text" field to remove line breaks.

The example is formatted for Unix, Linux, and macOS. For Windows, replace the backslash (\) Unix continuation character at the end of each line with a caret (^).

To translate text using a JSON file

1. Copy the following text into a JSON file called translate.json:

{

"Text": "Amazon Translate translates documents between languages in real time. It uses advanced machine learning technologies

to provide high-quality real-time translation. Use it to translate documents or to build applications that work in multiple languages.",

"SourceLanguageCode": "en", "TargetLanguageCode": "fr"

}

2. In the AWS CLI, run the following command:

aws translate translate-text \ --region region \

--cli-input-json file://translate.json > translated.json

The command outputs a JSON file that contains the following JSON text:

{ "TargetLanguageCode": "fr",

"Text": "Amazon Translate traduit les documents entre

(17)

Next Step

les langue en temps réel. Il utilise des technologies avancées d'apprentissage de la machine pour fournir une traduction en temps réel de haute qualité. Utilisez-le pour traduire des documents ou pour créer des applications qui fonctionnent en plusieurs langues.",

"SourceLanguageCode": "en"

}

Next Step

To see other ways to use Amazon Translate see Examples (p. 47).

Step 5: Getting Started (SDK)

The following examples demonstrate how to use Amazon Translate TranslateText (p. 142) operation using Java and Python. Use them to learn about the TranslateText operation and as building blocks for your own applications.

To run the Java examples, you need to install the AWS SDK for Java. For instructions for installing the SDK for Java, see Set up the AWS SDK for Java.

Topics

• Translating Text Using the AWS SDK for Java (p. 12)

• Translating Text Using the AWS SDK for Python (Boto) (p. 13)

• Translating Text Using the AWS Mobile SDK for Android (p. 15)

• Translating Text Using the AWS Mobile SDK for iOS (p. 16)

Translating Text Using the AWS SDK for Java

The following example demonstrates using the TranslateText (p. 142) operation in Java. To run this example, you need the AWS SDK for Java. For instructions for installing the SDK for Java, see Set up the AWS SDK for Java.

import com.amazonaws.auth.AWSStaticCredentialsProvider;

import com.amazonaws.auth.BasicAWSCredentials;

import com.amazonaws.client.builder.AwsClientBuilder;

import com.amazonaws.services.translate.AmazonTranslate;

import com.amazonaws.services.translate.AmazonTranslateClient;

import com.amazonaws.services.translate.model.TranslateTextRequest;

import com.amazonaws.services.translate.model.TranslateTextResult;

public class App {

private static final String REGION = "region";

public static void main( String[] args ) {

// Create credentials using a provider chain. For more information, see

// https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html AWSCredentialsProvider awsCreds = DefaultAWSCredentialsProviderChain.getInstance();

AmazonTranslate translate = AmazonTranslateClient.builder() .withCredentials(new

AWSStaticCredentialsProvider(awsCreds.getCredentials())) .withRegion(REGION)

(18)

Using the AWS SDK for Python

.build();

TranslateTextRequest request = new TranslateTextRequest() .withText("Hello, world")

.withSourceLanguageCode("en") .withTargetLanguageCode("es");

TranslateTextResult result = translate.translateText(request);

System.out.println(result.getTranslatedText());

} }

For a list of supported languages and language codes, see Supported Languages and Language Codes (p. 1)

Translating Text Using the AWS SDK for Python (Boto)

The following example demonstrates using the TranslateText (p. 142) operation in Python. To run it, you must first install Amazon Translate via the AWS CLI. For instructions, see the section called “Step 2:

Set Up the AWS CLI” (p. 8).

import boto3

translate = boto3.client(service_name='translate', region_name='region', use_ssl=True) result = translate.translate_text(Text="Hello, World",

SourceLanguageCode="en", TargetLanguageCode="de") print('TranslatedText: ' + result.get('TranslatedText'))

print('SourceLanguageCode: ' + result.get('SourceLanguageCode')) print('TargetLanguageCode: ' + result.get('TargetLanguageCode'))

For a list of supported language codes, see Supported Languages and Language Codes (p. 1) Custom Terminology

Another example, this one demonstrating using the Custom Terminology operations in Python:

#!/usr/bin/env python # -*- coding: utf-8 -*-

import boto3

translate = boto3.client(service_name='translate')

# The terminology file 'my-first-terminology.csv' has the following contents:

''' en,fr

Amazon Family,Amazon Famille '''

# Read the terminology from a local file

with open('/tmp/my-first-terminology.csv', 'rb') as f:

data = f.read()

file_data = bytearray(data)

print("Importing the terminology into Amazon Translate...")

response = translate.import_terminology(Name='my-first-terminology',

MergeStrategy='OVERWRITE', TerminologyData={"File": file_data, "Format": 'CSV'}) print("Terminology imported: "),

(19)

Using the AWS SDK for Python

print(response.get('TerminologyProperties')) print("\n")

print("Getting the imported terminology...")

response = translate.get_terminology(Name='my-first-terminology', TerminologyDataFormat='CSV')

print("Received terminology: "),

print(response.get('TerminologyProperties'))

print("The terminology data file can be downloaded here: " + response.get('TerminologyDataLocation').get('Location')) print("\n")

print("Listing the first 10 terminologies for the account...") response = translate.list_terminologies(MaxResults=10)

print("Received terminologies: "),

print(response.get('TerminologyPropertiesList')) print("\n")

print("Translating 'Amazon Family' from English to French with no terminology...") response = translate.translate_text(Text="Amazon Family", SourceLanguageCode="en", TargetLanguageCode="fr")

print("Translated text: " + response.get('TranslatedText')) print("\n")

print("Translating 'Amazon Family' from English to French with the 'my-first- terminology' terminology...")

response = translate.translate_text(Text="Amazon Family", TerminologyNames=["my-first- terminology"], SourceLanguageCode="en", TargetLanguageCode="fr")

print("Translated text: " + response.get('TranslatedText')) print("\n")

# The terminology file 'my-updated-terminology.csv' has the following contents:

''' en,fr

Amazon Family,Amazon Famille Prime Video, Prime Video '''

# Read the terminology from a local file

with open('/tmp/my-updated-terminology.csv', 'rb') as f:

data = f.read()

file_data = bytearray(data)

print("Updating the imported terminology in Amazon Translate...") response = translate.import_terminology(Name='my-first-terminology',

MergeStrategy='OVERWRITE', TerminologyData={"File": file_data, "Format": 'CSV'}) print("Terminology updated: "),

print(response.get('TerminologyProperties')) print("\n")

print("Translating 'Prime Video' from English to French with no terminology...") response = translate.translate_text(Text="Prime Video", SourceLanguageCode="en", TargetLanguageCode="fr")

print("Translated text: " + response.get('TranslatedText')) print("\n")

print("Translating 'Prime Video' from English to French with the 'my-first-terminology' terminology...")

response = translate.translate_text(Text="Prime Video", TerminologyNames=["my-first- terminology"], SourceLanguageCode="en", TargetLanguageCode="fr")

print("Translated text: " + response.get('TranslatedText')) print("\n")

print("Cleaning up by deleting 'my-first-terminology'...") translate.delete_terminology(Name="my-first-terminology")

(20)

Using the Mobile SDK for Android

print("Terminology deleted.")

Translating Text Using the AWS Mobile SDK for Android

You can use Amazon Translate in an Android application to translate text.

To configure the example

1. Set up the AWS Mobile SDK for Android. For instructions, see Android: Setup Options for the SDK in the AWS Mobile Developer Guide

2. Create an IAM user with the minimum required permissions to run this example. For information about creating an IAM user, see Creating an IAM User in Your AWS Account in the AWS Identity and Access Management User Guide. For the required permissions policies, see Amazon Translate Identity-Based Policies (p. 78). After you create the user, download the credentials or record the access key and secret access key.

3. Create a new project with Android Studio.

4. Add the following to the dependencies section of your build.gradle file.

dependencies {

implementation 'com.amazonaws:aws-android-sdk-translate:2.6.20' }

5. Add the following permissions to the AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

6. Copy the source code into your project

7. Change the access key and secret access key to the keys that you recorded in step one.

Code

Use the following code to create the example.

package com.amazonaws.amazontranslatetester;

import android.app.Activity;

import android.util.Log;

import com.amazonaws.auth.AWSCredentials;

import com.amazonaws.handlers.AsyncHandler;

import com.amazonaws.services.translate.AmazonTranslateAsyncClient;

import com.amazonaws.services.translate.model.TranslateTextRequest;

import com.amazonaws.services.translate.model.TranslateTextResult;

public class MainActivity extends Activity {

private static final String LOG_TAG = MainActivity.class.getSimpleName();

@Override

protected void onCreate(Bundle savedInstanceState) { AWSCredentials awsCredentials = new AWSCredentials() {

(21)

Using the Mobile SDK for iOS

@Override

public String getAWSAccessKeyId() { return "access key";

}

@Override

public String getAWSSecretKey() { return "secret key";

} };

AmazonTranslateAsyncClient translateAsyncClient = new AmazonTranslateAsyncClient(awsCredentials);

TranslateTextRequest translateTextRequest = new TranslateTextRequest() .withText("Hello, world")

.withSourceLanguageCode("en") .withTargetLanguageCode("es");

translateAsyncClient.translateTextAsync(translateTextRequest, new AsyncHandler<TranslateTextRequest, TranslateTextResult>() {

@Override

public void onError(Exception e) {

Log.e(LOG_TAG, "Error occurred in translating the text: " + e.getLocalizedMessage());

}

@Override

public void onSuccess(TranslateTextRequest request, TranslateTextResult translateTextResult) {

Log.d(LOG_TAG, "Original Text: " + request.getText());

Log.d(LOG_TAG, "Translated Text: " + translateTextResult.getTranslatedText());

} });

} }

Translating Text Using the AWS Mobile SDK for iOS

You can use Amazon Translate in an iOS application to translate text.

To configure the example

1. Create an IAM user with the minimum required permissions to run this example. For information about creating an IAM user, see Creating an IAM User in Your AWS Account in the AWS Identity and Access Management User Guide. For the required permissions policies, see Amazon Translate Identity-Based Policies (p. 78). After you create the user, download the credentials or record the access key and secret access key.

2. Install Xcode version 8.0 or later. You can download the latest version of Xcode from the Apple website, https://developer.apple.com/xcode/.

3. Install Cocoapods. In a terminal window, run the following command:

sudo gem install cocoapods

4. Create a project using Xcode. Then, in a terminal window, navigate to the directory that contains your project's .xcodeproj file and run the following command:

pod init

(22)

Using the Mobile SDK for iOS

5. Add the core Mobile SDK for iOS components to your pod file:

platform :ios, '9.0' target :'app name' do use_frameworks!

pod 'AWSTranslate', '~> 2.6.19' # other pods

end

6. Install dependencies by running the following command in a terminal window:

pod install --repo-update

7. Running 'pod install' creates a new workspace file. Close your Xcode project and then open it using the ./project_name.xcworkspace file. From now on you should only use this file to open your Xcode project

Rebuild your app after you open it to resolve APIs from the new libraries called in your code.

8. Add the following import statement to your view controller:

import AWSTranslate

9. Copy the following code into your XCode project. Update the access key and secret key to the values that you recorded in step 1.

Code

Use the following code to create the example.

var credentialsProvider = AWSStaticCredentialsProvider(accessKey: "access key", secretKey:

"secret key")

var configuration = AWSServiceConfiguration(region: AWSRegionUSEast1, credentialsProvider:

credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = configuration let translateClient = AWSTranslate.default()

let translateRequest = AWSTranslateTranslateTextRequest() translateRequest?.sourceLanguageCode = "en"

translateRequest?.targetLanguageCode = "es"

translateRequest?.text = "Hello World"

let callback: (AWSTranslateTranslateTextResponse?, Error?) -> Void = { (response, error) in guard let response = response else {

print("Got error \(error)") return

}

if let translatedText = response.translatedText { print(translatedText)

}}

translateClient.translateText(translateRequest!, completionHandler: callback)

(23)

Real-Time Translation

Translation Processing Modes

When translating documents, you can use two different translation processing modes: real-time translation or asynchronous batch processing. The mode you use is based on the size and type of the target documents and affects how you submit the translation job and view its results.

• Real-time translation (p. 18) – You call Amazon Translate on a small field of text and a synchronous response is immediately sent to your application.

• Asynchronous batch processing (p. 18) – You put a collection of documents in an Amazon Simple Storage Service (Amazon S3) bucket and start an asynchronous processing job to translate them.

Amazon Translate sends the translated output document to a specified Amazon S3 bucket.

Real-Time Translation

To translate a single text document and return the results of that translation directly to your application, use the Amazon Translate real-time translation operation, TranslateText (p. 142). Use this translation mode for interactive applications that work on one document at a time.

For an example of a real-time translation workflow, see Translate Text Using the Command Line (p. 11).

Asynchronous Batch Processing with Amazon Translate

To translate large collections of documents (up to 5 GB in size), use the Amazon Translate asynchronous batch processing operation, StartTextTranslationJob (p. 135). This is best for collections of short documents, such as social media postings or user reviews, or any situation in which instantaneous translation is not required.

To perform an asynchronous batch translation, you typically perform the following steps:

1. Store a set of documents in an input folder inside of an Amazon S3 bucket.

2. Start a batch translation job.

3. As part of your request, provide Amazon Translate with an IAM role that has read access to the input Amazon S3 folder. The role must also have read and write access to an output Amazon S3 bucket.

4. Monitor the progress of the batch translation job.

5. Retrieve the results of the batch translation job from the specified output bucket.

Region Availability

Batch translation is supported in the following AWS Regions:

• US East (N. Virginia)

• US East (Ohio)

• US West (Oregon)

• Asia Pacific (Seoul)

• Europe (Frankfurt)

(24)

Prerequisites

• Europe (Ireland)

• Europe (London)

Prerequisites for Batch Translation Jobs

The following prerequisites must be met in order for Amazon Translate to perform a successful batch translation job:

• The Amazon S3 buckets that contain your input and output documents must be in the same AWS Region as the API endpoint you are calling.

• The collection of batch input documents must be 5 GB or less in size.

• There can be a maximum of one million documents submitted in a batch translation job.

• Each input document must be 20 MB or less and must contain fewer than 1 million characters.

• Your input files must be in a folder in an Amazon S3 bucket. If your files are not in a folder, and they reside at the top level of a bucket, Amazon Translate throws an error when you attempt to run a batch translation job. This requirement applies only to input files. No folder is necessary for the output files, and Amazon Translate can place them at the top level of an Amazon S3 bucket.

Supported File Formats

Amazon Translate supports the following types of files for batch translation jobs:

• Plain text.

• HTML.

• Word documents (.docx).

• PowerPoint Presentation files (.pptx).

• Excel Workbook files (.xlsx).

• XML Localization Interchange File Format (XLIFF) files (.xlf). Amazon Translate supports only XLIFF version 1.2.

Amazon Translate requires files to be UTF-8 encoded.

Prerequisite Permissions

Before you can run a batch translation job, your AWS account must have a service role in IAM. This role must have a permissions policy that grants Amazon Translate:

• Read access to your input folder in Amazon S3.

• Read and write access to your output bucket.

It must also include a trust policy that allows Amazon Translate to assume the role and gain its

permissions. This trust policy must allow the translate.amazonaws.com service principal to perform the sts:AssumeRole action.

When you create a batch translation job by using the Amazon Translate console, you have the option to allow Amazon Translate to automatically create this role for you. When you run a batch translation job by using the AWS CLI or the Amazon Translate API, you provide the Amazon Resource Name (ARN) of the role in your request.

For more information, see Creating a Role to Delegate Permissions to an AWS Service in the IAM User Guide.

(25)

Prerequisites

Example Permissions Policy

The following example permissions policy grants read access to an input folder in an Amazon S3 bucket.

It grants read and write access to an output bucket.

{

"Version": "2012-10-17", "Statement": [

{

"Effect": "Allow", "Action": "s3:GetObject", "Resource": [

"arn:aws:s3:::input-bucket-name/*", "arn:aws:s3:::output-bucket-name/*"

] }, {

"Effect": "Allow",

"Action": "s3:ListBucket", "Resource": [

"arn:aws:s3:::input-bucket-name", "arn:aws:s3:::output-bucket-name"

] }, {

"Effect": "Allow", "Action": [

"s3:PutObject"

],

"Resource": "arn:aws:s3:::output-bucket-name/*"

} ]}

Example Trust Policy

The following trust policy allows Amazon Translate to assume the IAM role that the policy belongs to.

We recommend that you verify the AWS account that is using the trust policy, to mitigate the Confused deputy problem. This example uses the aws:SourceArn and aws:SourceAccount condition keys to verify the source account. Enter the AWS account that submits the batch translation job.

{ "Version": "2012-10-17", "Statement": [

{

"Effect": "Allow", "Principal": {

"Service": "translate.amazonaws.com"

},

"Action": "sts:AssumeRole", "Condition": {

"ArnLike": {

"aws:SourceArn": "arn:aws:translate:*:111122223333:*"

},

"StringEquals": {

"aws:SourceAccount": "111122223333"

} } } ]}

(26)

Prerequisites

Prerequisite Permissions to Customize Encryption

You can customize your encryption settings in Amazon Translate, but first you must add permissions to the service role in IAM.

Amazon Translate encrypts the translation output that you produce when you run a batch translation job. By default, it does this encryption with an AWS managed key. This type of key is created by AWS and stored in AWS Key Management Service (AWS KMS) in your account. However, you cannot manage this KMS key yourself. It is managed and used on your behalf only by AWS.

Optionally, you can choose to encrypt your output with a customer managed key, which is a KMS key that you create, own, and manage in your AWS account.

Your key must have a key policy that enables Amazon Translate to use it. The key policy does this by granting its permissions to the service role that allows Amazon Translate to access your Amazon S3 bucket.

The key policy allows the service role to perform the AWS KMS operations that are required to encrypt your output, as shown by the following example policy statement.

Example KMS key policy statement

{

"Effect": "Allow", "Principal":

{ "AWS":

[

"arn:aws:iam::111122223333:role/AmazonTranslateServiceRoleS3FullAccess"

] }, "Action":

[

"kms:Decrypt",

"kms:GenerateDataKey", "kms:CreateGrant", "kms:RetireGrant", "kms:DescribeKey"

], "Resource": "*"

}

For more information, see Key policies in AWS KMS in the AWS Key Management Service Developer Guide

Permissions to Use an AWS KMS Key from Another AWS Account

If you want to use a KMS key that's in a different AWS account from the one where you use Amazon Translate, then you must:

1. Update the service role for Amazon Translate in IAM.

2. Update the key policy in AWS KMS.

To update your service role, attach a policy that allows it to perform the necessary AWS KMS operations with the KMS key that's in the other AWS account, as shown by the following example.

Example IAM policy to grant access to a KMS key in a different account

{

(27)

Running a Job

"Effect": "Allow", "Action":

[ "kms:Decrypt",

"kms:GenerateDataKey", "kms:CreateGrant", "kms:RetireGrant", "kms:DescribeKey"

],

"Resource": "arn:aws:kms:us-west-2:111122223333:key/key-id"

}

To update your KMS key policy, add the service role and root user as principals that are allowed to use the key, as shown by the following example policy statement.

Example KMS key policy statement to allow an IAM role to use the key

{

"Effect": "Allow", "Principal":

{ "AWS":

[

"arn:aws:iam::444455556666:role/AmazonTranslateServiceRoleS3FullAccess", "arn:aws:iam::444455556666:root"

] }, "Action":

[ "kms:Decrypt", "kms:CreateGrant", "kms:GenerateDataKey", "kms:RetireGrant", "kms:DescribeKey"

],

"Resource": "*"

}

For more information, see Allowing users in other accounts to use a KMS key in the AWS Key Management Service Developer Guide

Running a Batch Translation Job

You can run a batch translation job by using the Amazon Translate console, the AWS CLI, or the Amazon Translate API.

Notes

• Batch translation jobs are long-running operations and can take significant time to complete.

For example, batch translation on a small dataset might take a few minutes, while very large datasets may take up to 2 days or more. Completion time is also dependent on the availability of resources.

• Amazon Translate does not automatically detect a source language during batch translation jobs.

Amazon Translate Console

To run a translation job by using the Amazon Translate console, use the Batch translation page to create the job:

(28)

Running a Job

1. Open the Amazon Translate console at https://console.aws.amazon.com/translate/

2. In the navigation menu on the left, choose Batch translation.

3. On the Translation jobs page, choose Create job. The console shows the Create translation job page.

4. Under Job settings, do the following:

a. For Name, enter a custom name for the batch translation job.

b. For Source language, select the language of the source files that are being translated.

c. For Target language, select language that your files are translated into.

5. Under Input data, do the following:

a. For Input S3 location, specify the input folder that contains the translation source files in Amazon S3. To provide the folder by navigating to it in Amazon S3, choose Select folder.

b. For File format, select format of the translation source files.

6. Under Output data, do the following:

a. For Output S3 location, specify the output folder in Amazon S3 where Amazon Translate puts the translation output. To provide the folder by navigating to it in Amazon S3, choose Select folder.

b. Optionally, choose Customize encryption settings (advanced) if you want to encrypt your output with a customer managed key that you manage in AWS Key Management Service (AWS KMS).

By default, Amazon Translate encrypts your translation output using a KMS key that is created, managed, and used on your behalf by AWS. Choose this option if you want to encrypt your output with your own KMS key instead.

If you want to use a KMS key from the current AWS account, select it under Choose an AWS KMS key. Or, if you want to use a KMS key from a different AWS account, enter the Amazon Resource Name (ARN) for that key.

NoteBefore you can use your own KMS key, you must add permissions to the service role for Amazon Translate in IAM. If you want to use a KMS key from a different account, you must also update the key policy in AWS KMS. For more information, see Prerequisite Permissions to Customize Encryption (p. 21).

7. Under Customizations - optional, you can choose to customize the output of your translation job with the following settings:

Profanity

Enable to mask profane words and phrases in your translation output. For more information, see Masking Profane Words and Phrases in Amazon Translate (p. 29).

Formality

The formality option is not available for batch translation jobs.

Custom terminology

Consists of example source terms and the desired translation for each term.

For more information, see Customizing Your Translations with Custom Terminology (p. 31).

Parallel data

Consists of examples that show how you want segments of text to be translated. When you add parallel data to a batch translation job, you create an Active Custom Translation job.

(29)

Running a Job

NoteActive Custom Translation jobs are priced at a higher rate than other jobs that don't use parallel data. For more information, see Amazon Translate pricing.

For more information, see Customizing Your Translations with Parallel Data (Active Custom Translation) (p. 36).

8. Under Access permissions, provide Amazon Translate with an IAM role that grants the required permissions to your input and output files in Amazon S3:

• If you already have this IAM role in your account, choose Use an existing IAM role, and select it under IAM role.

• If you don't already have this IAM role in your account, choose Create an IAM role. For IAM role, choose Input and output S3 buckets. For Role name, provide a custom name. When you create the translation job, Amazon Translate creates the role automatically. The role name in IAM is prefixed with AmazonTranslateServiceRole-.

NoteIf you chose to encrypt your translation output with your own KMS key, then you cannot choose Create an IAM role. In this case, you must use a preexisting IAM role, and your KMS key must have a key policy that allows the role to use the key.

For more information, see Prerequisite Permissions to Customize Encryption (p. 21) 9. Choose Create job.

The console returns to the Translation jobs page, where the job creation status is shown in a banner at the top of the page. After a few minutes, your job is shown in the table.

10. Choose the job name in the Name column to open the job details page.

While your translation job runs, the Status field shows In progress.

11. When the status becomes Completed, go to your translation output by choosing the link under Output file location. The console goes to your output bucket in Amazon S3.

12. To download your output files, select the check box for each, and choose Download.

AWS CLI

To run a translation job by using the AWS CLI, use the start-text-translation-job command, and specify the name of your parallel data resource for the parallel-data-names parameter.

Example start-text-translation-job command

The following example runs a translation job by submitting an Excel file that is stored in an input bucket in Amazon S3. This job is customized by the parallel data that is included in the request.

$ aws translate start-text-translation-job \

> --input-data-config ContentType=application/vnd.openxmlformats- officedocument.spreadsheetml.sheet,S3Uri=s3://my-s3-bucket/input/ \

> --output-data-config S3Uri=s3://my-s3-bucket/output/ \

> --data-access-role-arn arn:aws:iam::111122223333:role/my-iam-role \

> --source-language-code=en \

> --target-language-codes=es \

> --job-name my-translation-job

If the command succeeds, Amazon Translate responds with the job ID and status:

{ "JobId": "4446f95f20c88a4b347449d3671fbe3d", "JobStatus": "SUBMITTED"

(30)

Running a Job

}

If you want to customize the output of your translation job, you can use the following parameters:

--settings

Settings to configure your translation output, including the option to mask profane words and phrases. To enable profanity masking, set this parameter to Profanity=MASK. For more information, see Masking Profane Words and Phrases in Amazon Translate (p. 29).

--terminology-names

The name of a custom terminology resource to add to the translation job. This resource lists example source terms and the desired translation for each term.

This parameter accepts only one custom terminology resource.

For a list of available custom terminology resources, use the list-terminologies command.

For more information, see Customizing Your Translations with Custom Terminology (p. 31).

--parallel-data-names

The name of a parallel data resource to add to the translation job. This resource consists of examples that show how you want segments of text to be translated. When you add parallel data to a

translation job, you create an Active Custom Translation job.

This parameter accepts only one parallel data resource.

Note

Active Custom Translation jobs are priced at a higher rate than other jobs that don't use parallel data. For more information, see Amazon Translate pricing.

For a list of available parallel data resources, use the list-parallel-data command.

For more information, see Customizing Your Translations with Parallel Data (Active Custom Translation) (p. 36).

To check the status of your translation job, use the describe-text-translation-job command.

Example describe-text-translation-job command

The following example checks the job status by providing the job ID. This ID was provided by Amazon Translate when the job was initiated by the start-text-translation-job command.

$ aws translate describe-text-translation-job \

> --job-id 4446f95f20c88a4b347449d3671fbe3d

Amazon Translate responds with the job properties, which include its status:

{ "TextTranslationJobProperties": {

"JobId": "4446f95f20c88a4b347449d3671fbe3d", "JobName": "my-translation-job",

"JobStatus": "COMPLETED", "JobDetails": {

"TranslatedDocumentsCount": 0, "DocumentsWithErrorsCount": 0, "InputDocumentsCount": 1 },

"SourceLanguageCode": "en", "TargetLanguageCodes": [

(31)

Monitoring and Analyzing

"es"

],

"SubmittedTime": 1598661012.468, "InputDataConfig": {

"S3Uri": "s3://my-s3-bucket/input/",

"ContentType": "application/vnd.openxmlformats- officedocument.spreadsheetml.sheet"

},

"OutputDataConfig": {

"S3Uri": "s3://my-s3-bucket/output/111122223333- TranslateText-4446f95f20c88a4b347449d3671fbe3d/"

},

"DataAccessRoleArn": "arn:aws:iam::111122223333:role/my-iam-role"

} }

If the JobStatus value is IN_PROGRESS, allow a few minutes to pass, and run describe-text- translation-job again until the status is COMPLETED. When the job completes, you can download the translation results at the location provided by the S3Uri field under OutputDataConfig.

Amazon Translate API

To submit a batch translation job by using the Amazon Translate API, use the StartTextTranslationJob (p. 135) operation.

Monitoring and Analyzing Batch Translation Jobs

You can use a job's ID to monitor its progress and get the Amazon S3 location of its output documents.

To monitor a specific job, use the DescribeTextTranslationJob (p. 114) operation. You can also use the ListTextTranslationJobs (p. 132) operation to retrieve information on all of the translation jobs in your account. To restrict results to jobs that match a certain criteria, use the ListTextTranslationJobs (p. 132) operation's filter parameter. You can filter results by job name, job status, or the date and time that the job was submitted.

Example describe-text-translation-job command

The following example check's a job's status by using the AWS CLI to run the describe-text-translation- job command:

$ aws translate describe-text-translation-job --job-id 1c1838f470806ab9c3e0057f14717bed

This command returns the following output:

{ "TextTranslationJobProperties": { "InputDataConfig": {

"ContentType": "text/plain",

"S3Uri": "s3://input-bucket-name/folder"

},

"EndTime": 1576551359.483, "SourceLanguageCode": "en",

"DataAccessRoleArn": "arn:aws:iam::012345678901:role/service-role/

AmazonTranslateInputOutputAccess",

"JobId": "1c1838f470806ab9c3e0057f14717bed", "TargetLanguageCodes": [

"fr"

],

"JobName": "batch-test",

"SubmittedTime": 1576544017.357, "JobStatus": "COMPLETED",

(32)

Getting Results

"Message": "Your job has completed successfully.", "JobDetails": {

"InputDocumentsCount": 77, "DocumentsWithErrorsCount": 0, "TranslatedDocumentsCount": 77 },

"OutputDataConfig": {

"S3Uri": "s3://bucket-name/output/012345678901- TranslateText-1c1838f470806ab9c3e0057f14717bed/"

} } }

You can stop a batch translation job while its status is IN_PROGRESS by using the StopTextTranslationJob (p. 140) operation.

Example stop-text-translation-job command

The following example stops a batch translation with by using the AWS CLI to run the stop-text- translation-job command:

$ aws translate stop-text-translation-job --job-id 5236d36ce5192abdb3e2519f3ab8b065

This command returns the following output:

{

"TextTranslationJobProperties": { "InputDataConfig": {

"ContentType": "text/plain",

"S3Uri": "s3://input-bucket-name/folder"

},

"SourceLanguageCode": "en",

"DataAccessRoleArn": "arn:aws:iam::012345678901:role/service-role/

AmazonTranslateInputOutputAccess", "TargetLanguageCodes": [ "fr"

],

"JobName": "canceled-test", "SubmittedTime": 1576558958.167, "JobStatus": "STOP_REQUESTED",

"JobId": "5236d36ce5192abdb3e2519f3ab8b065", "OutputDataConfig": {

"S3Uri": "s3://output-bucket-name/012345678901- TranslateText-5236d36ce5192abdb3e2519f3ab8b065/"

} } }

Getting Batch Translation Results

Once the job's status is COMPLETED or COMPLETED_WITH_ERROR, your output documents are available in the Amazon S3 folder you specified. The output document names match the input document names, with the addition of the target language code as a prefix. For instance, if you translated a document called mySourceText.txt into French, the output document will be called fr.mySourceText.txt.

If the status of a batch translation job is FAILED, the DescribeTextTranslationJob (p. 114) operation response includes a Message field that describes the reason why the job didn't complete successfully.

Each batch translation job also generates an auxiliary file that contains information on the translations performed, such as the total number of characters translated and the number of errors encountered.

(33)

Getting Results

This file, called target-language-code.auxiliary-translation-details.json, is generated in the details subfolder of your output folder.

The following is an example of a batch translation auxiliary file.

{

"sourceLanguageCode": "en", "targetLanguageCode": "fr", "charactersTranslated": "105",

"documentCountWithCustomerError": "0", "documentCountWithServerError": "0",

"inputDataPrefix": "s3://input-bucket-name/folder", "outputDataPrefix": "s3://output-bucket-name/012345678901- TranslateText-1c1838f470806ab9c3e0057f14717bed/",

"details": [ {

"sourceFile": "mySourceText.txt", "targetFile": "fr.mySourceText.txt", "auxiliaryData": {

"appliedTerminologies": [ {

"name": "TestTerminology", "terms": [

{

"sourceText": "Amazon", "targetText": "Amazon"

} ] } ] } }, {

"sourceFile": "batchText.txt", "targetFile": "fr.batchText.txt", "auxiliaryData": {

"appliedTerminologies": [ {

"name": "TestTerminology", "terms": [

{

"sourceText": "Amazon", "targetText": "Amazon"

} ] } ] } } ]}

(34)

Masking Profanity

Customizing Your Translations with Amazon Translate

You can use the following settings to customize the translations that you produce with Amazon Translate:

Profanity – Enable this option to mask profane words and phrases in your translation output.

Formality – Enable this option to set the level of language formality in your translation output.

Custom terminology – Defines how you want Amazon Translate to translate specific terms, such as brand names.

Parallel data – Consists of segments of example source text and their translations. When you

customize a job with parallel data, Amazon Translate adapts the translation output to reflect the style, tone, and word choices that it finds in the example translations.

Topics

• Masking Profane Words and Phrases in Amazon Translate (p. 29)

• Setting Formality in Amazon Translate (p. 30)

• Customizing Your Translations with Custom Terminology (p. 31)

• Customizing Your Translations with Parallel Data (Active Custom Translation) (p. 36)

Masking Profane Words and Phrases in Amazon Translate

When you run translations with Amazon Translate, you can enable the profanity setting to mask profane words and phrases in your translation output.

To mask profane words and phrases, Amazon Translate replaces them with the grawlix string “?$#@$“.

This 5-character sequence is used for each profane word or phrase, regardless of the length or number of words.

Amazon Translate does not mask profanity in translation requests where the source language and target language are the same.

In some cases, a profane word in the source input might naturally become inoffensive in the translated output. In such cases, no masking is applied.

Amazon Translate detects each profane word or phrase literally, not contextually. This means that it might mask a profane word even if it’s inoffensive in context. For example, if Amazon Translate detected

“jerk” as a profane word, then it would write the phrase “jerk chicken” as “?$#@$ chicken”, even though

“jerk chicken” is inoffensive. (Here, “jerk” is used as an example only. Amazon Translate does not detect that word as profanity.)

Using the Profanity Setting

You can use the profanity setting with both types of translation operations in Amazon Translate: real- time translation and asynchronous batch processing.

(35)

Unsupported Languages

To mask profanity in a real-time translation request, do any of the following:

• On the Real-time translation page in the Amazon Translate console, under Additional settings, enable the Profanity setting.

• For translate-text command in the AWS CLI, set the --settings parameter to

Profanity=MASK. For more information, see translate-text in the AWS CLI Command Reference.

• Use the Settings parameter in the TranslateText action in the Amazon Translate API.

To mask profanity in an asynchronous batch operation, see Running a Batch Translation Job (p. 22).

Unsupported Languages

You can mask profanity when you translate to any of the target languages that Amazon Translate supports, with the following exceptions:

Language Language Code

Bengali bn

Hindi hi

Malayalam ml

Punjabi pa

Sinhala si

Vietnamese vi

For all of the languages that Amazon Translate supports, see Supported Languages and Language Codes (p. 1).

Setting Formality in Amazon Translate

You can optionally specify the desired level of formality for translations to supported target languages.

The formality setting controls the level of formal language usage (also known as honorifics or register) in the translation output. The formality option is available for real-time translation mode but is not available for asynchronous batch processing.

Formality supports the following values:

Informal – All sentences in the translated text use language constructs associated with informal communication. For example, translated text uses the familiar form of second person pronouns and their verb agreement (or Kudaketa form for Japanese).

Formal – All sentences in the translated text use language constructs associated with formal, polite communication. For example, translated text uses the formal form of second person pronouns and their verb agreement (or Teineigo form for Japanese).

For example, the sentence ‘Are you sure?’ can have two correct translations in German: ‘Sind Sie sicher?’

for the formal register and ‘Bist du sicher?’ for the informal one.

If Amazon Translate doesn’t support formality level for the target language, or you don't specify the formality parameter, the translation job ignores the formality setting.

(36)

Using the Formality Setting

Using the Formality Setting

To set formality in a real-time translation request, do any of the following:

• On the Real-time translation page in the Amazon Translate console, under Additional settings, enable the Formality setting and select one of the values.

• For the translate-text command in the AWS CLI, set the --settings parameter to

Formality=FORMAL or Formality=INFORMAL. For more information, see translate-text in the AWS CLI Command Reference.

The translate-text response includes the formality setting (if any) from the request. If the target language doesn't support formality, the AppliedSettings value in the response is NULL.

• Use the Settings parameter in the TranslateText action in the Amazon Translate API.

Formality is not available for asynchronous batch operations.

Supported Languages

Amazon Translate supports the formality setting for translation from any source language to the following target languages.

Language Language Code

French fr

German de

Hindi hi

Italian it

Japanese ja

Spanish es

For all the languages that Amazon Translate supports, see Supported Languages and Language Codes (p. 1).

Customizing Your Translations with Custom Terminology

Using custom terminology with your translation requests enables you to make sure that your brand names, character names, model names, and other unique content is translated exactly the way you need it, regardless of its context and the Amazon Translate algorithm’s decision.

It's easy to set up a terminology file and attach it to your Amazon Translate account. When you translate text, you simply choose to use the custom terminology as well, and any examples of your source word are translated as you want them.

For example, consider the following: Amazon Family is a collection of benefits that offers Amazon Prime members exclusive offers, such as up to 20% off subscriptions to diapers, baby food, and more. In France, it's called Amazon Famille. If you translate Amazon Family into French using Amazon Translate without

參考文獻

相關文件

The Chinese Language Education (CLE) Section is responsible for curriculum development related to Chinese Language education as well as organising professional development

- allow students to demonstrate their learning and understanding of the target language items in mini speaking

• helps teachers collect learning evidence to provide timely feedback &amp; refine teaching strategies.. AaL • engages students in reflecting on &amp; monitoring their progress

Students are able to use different learning strategies such as inquiry, reasoning, and problem solving skills in various learning activities. Teachers will employ a variety

• Among the learning objectives for ELEKLA, the language development strategies, literary competence development strategies and attitudes specific to language and literature

• Among the learning objectives for ELEKLA, the language development strategies, literary competence development strategies and attitudes specific to language and literature

Building on the strengths of students and considering their future learning needs, plan for a Junior Secondary English Language curriculum to gear students towards the

Language Curriculum: (I) Reading and Listening Skills (Re-run) 2 30 3 hr 2 Workshop on the Language Arts Modules: Learning English. through Popular Culture (Re-run) 2 30