

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用自訂術語自訂翻譯
<a name="how-custom-terminology"></a>

使用自訂術語與您的翻譯請求，以確保您的品牌名稱、角色名稱、模型名稱和其他唯一內容已翻譯為所需的結果。

您可以建立術語檔案，並將其上傳至您的 Amazon Translate 帳戶。如需有關檔案大小和術語檔案數量的資訊，請參閱 [Service Quotas](what-is-limits.md#limits)。翻譯文字時，您可以選擇是否要使用的自訂術語檔案。當 Amazon Translate 找到來源文字與術語檔案之間的相符項目時，它會使用術語檔案中的轉譯。

請考慮下列範例：*Amazon Photos* 為 Amazon Prime 成員提供免費的相片和影片儲存。在法文中，名稱不會翻譯：它仍為 *Amazon Photos*。

當您使用 Amazon Translate 將 *Amazon Photos* 翻譯為法文，而沒有任何其他內容時，結果是 *Photos d'Amazon*，這不是所需的翻譯。

如果您為 *Amazon Photos* 一詞新增自訂術語項目，指定法文翻譯為 *Amazon Photos*，Amazon Translate 會使用自訂術語將片語翻譯為所需的結果。

Amazon Translate 不保證會針對每個轉譯使用目標詞彙。自訂術語使用轉譯內容中來源和目標術語的意義來決定是否使用目標術語。如需詳細資訊，請參閱[最佳實務](ct-best-practices.md)。

**Topics**
+ [建立自訂術語](creating-custom-terminology.md)
+ [使用自訂術語](using-ct.md)
+ [使用 的自訂術語範例 適用於 Python (Boto) 的 AWS SDK](examples-ct.md)
+ [加密您的術語](protect-terminology.md)
+ [最佳實務](ct-best-practices.md)

# 建立自訂術語
<a name="creating-custom-terminology"></a>

您可以透過建立術語檔案來定義自訂術語。Amazon Translate 支援 CSV、TSV 或 TMX 檔案格式。檔案中的每個項目都包含每個目標語言的來源術語和同等 （已翻譯） 術語。

建立術語檔案之後，您會將檔案上傳至 Amazon Translate 帳戶。

**重要**  
自訂術語中的來源文字*區分大小寫*。在翻譯期間，Amazon Translate 在輸入文件中找到完全相符項目時，會使用自訂術語。

## 術語檔案格式
<a name="creating-custom-terminology-examples"></a>

下列範例顯示 CSV 格式的術語檔案。

**CSV (逗號分隔值)**

```
en,fr,es
Amazon Photos,Amazon Photos,Amazon Photos
```

下列範例顯示 TMX 格式的術語檔案。TMX 檔案使用翻譯軟體常用的 XML 格式。

**TMX (翻譯記憶 eXchange) **

```
<?xml version="1.0" encoding="UTF-8"?>
 <tmx version="1.4">
  <header
     creationtool="XYZTool" creationtoolversion="0"
     datatype="PlainText" segtype="sentence"
     adminlang="en-us" srclang="en"
     o-tmf="test"/>
  <body>
    <tu>
      <tuv xml:lang="en">
        <seg>Amazon Photos</seg>
      </tuv>
      <tuv xml:lang="fr">
        <seg>Amazon Photos</seg>
      </tuv>
      <tuv xml:lang="es">
        <seg>Amazon Photos</seg>
      </tuv>
    </tu>   
  </body>
 </tmx>
```

## 方向性
<a name="creating-custom-terminology-directionality"></a>

當您上傳自訂術語檔案時，您可以設定自訂術語的*方向性*值。方向性表示您的術語檔案指定一種來源語言或多種來源語言。

針對方向性，請設定下列其中一個值：

**單向**  
術語檔案包含一種來源語言 （清單中的第一個語言）。所有其他語言都是目標語言。  
例如，在 CSV 檔案中，第一欄包含來源語言的文字，而所有其他欄則包含目標語言的文字。

**多向**  
檔案中的任何語言可以是來源語言或目標語言。例如，如果您的術語檔案包含英文、法文和西班牙文的文字，您可以將該檔案用於翻譯下列語言對的任務：  
+ 英文到法文
+ 英文到西班牙文
+ 法文到英文
+ 從法文到西班牙文
+ 西班牙文到英文
+ 西班牙文到法文

相反地，您需要為這六個翻譯任務建立三個單向術語檔案 （每個來源語言一個）。

# 使用自訂術語
<a name="using-ct"></a>

若要在使用 [TranslateText](https://docs.aws.amazon.com/translate/latest/APIReference/API_TranslateText.html) 操作翻譯文字時使用自訂術語，請包含選用`TerminologyNames`參數。

例如，如果您將名為 的下列術語檔案上傳至`Amazon_Family.csv`您的帳戶：

```
     en,fr
     Amazon Family,Amazon Famille
```

您可以使用下列 CLI 命令，使用自訂術語翻譯文字。

**注意**  
此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
aws translate translate-text \
     --region region \
     --source-language-code "en" \
     --target-language-code "fr" \
     --terminology-names "Amazon_Family" \
     --text "Have you ever stored videos in Amazon Family?"
```

這使用選取的自訂術語，將此文字翻譯為「Avez-vous déjà fait des achats avec Amazon Famille？」 而不是直接 （但不想要） 翻譯 "Avez-vous déjà fait des achats avec Famille Amazon？"

下列範例示範如何在 Python 中使用相同的術語檔案。

```
import boto3
     
translate = boto3.client(service_name='translate')
  
print("Translating 'Have you ever shopped with Amazon Family?' from English to French with the 'Amazon_Family' custom terminology...")
response = translate.translate_text(Text="Have you ever shopped with Amazon Family?", TerminologyNames=["Amazon_Family"], SourceLanguageCode="en", TargetLanguageCode="fr")
print("Translated text: " + response.get('TranslatedText'))
print("\n")
```

如需搭配自訂術語使用 Amazon Translate 操作的詳細資訊，請參閱 [API 操作](https://docs.aws.amazon.com/translate/latest/APIReference/API_Operations.html)。

# 使用 的自訂術語範例 適用於 Python (Boto) 的 AWS SDK
<a name="examples-ct"></a>

下列範例示範如何在 Python 中使用自訂術語操作。若要執行範例，請透過 安裝 Python SDK AWS CLI。如需說明，請參閱「[安裝和設定 AWS Command Line Interface (AWS CLI)](setting-up.md#setup-awscli)」。

```
    #!/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: "),
    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")
    print("Terminology deleted.")
```

# 加密您的術語
<a name="protect-terminology"></a>

Amazon Translate 竭盡全力保護您的所有資料，而您的自訂術語也不例外。在建立時，每個自訂術語都會經過加密，只有您能存取。

共有三種加密選項可用：
+ 使用 AWS encryption. AWS encryption 是保護您的資訊的預設選項。
+ 使用與您的帳戶相關聯的加密金鑰。主控台中的功能表可讓您選擇要使用的相關聯加密金鑰。
+ 使用與您的帳戶無關的加密金鑰。主控台會顯示輸入欄位，供您輸入加密金鑰的 Amazon Resource Name (ARN)。

# 最佳實務
<a name="ct-best-practices"></a>

使用自訂術語時，請使用下列一般最佳實務：
+ 讓您的自訂術語保持簡潔。僅包含您需要控制翻譯值的詞彙。
+ 自訂術語會區分大小寫。如果您想要文字大寫和非大寫版本的目標轉譯，請包含每個版本的項目。
+ 自訂術語不是用來控制間距、標點符號或大小寫的工具。例如，避免下列類型的項目：
  + 新增空格 – EN：USA FR：U S A
  + 新增標點符號 – 英文：美國法文：美國
  + 變更大寫 – EN：USA FR：Usa
+ 請勿為相同的來源片語包含不同的轉譯。例如：
  + 項目編號 1 – 英文：Amazon FR：Amazon
  + 項目編號 2 – 英文：Amazon FR：Amazone
+ 您可以為 Amazon Translate 支援的任何語言建立自訂術語檔案。

Amazon Translate 不保證自訂術語會針對每個轉譯使用目標術語。若要使用自訂術語達到高準確度，請在建立術語檔案的內容時遵循以下最佳實務：
+ 自訂術語可與任何單字搭配使用，包括動詞和同義詞。正確名稱，例如品牌名稱和產品名稱，是理想的項目。
+ 目標術語在目標語言中應流暢。對於包含許多特殊字元或格式的目標術語，不建議使用自訂術語。
+ 您可以在術語檔案中包含多字片語或子句。不過，包含多個單字的術語不太可能以目標語言流暢讀取。
+ 自訂術語使用轉譯內容中來源和目標術語的意義，來決定是否使用目標術語。如果目標術語不適合特定翻譯內容，Amazon Translate 可能不會使用目標術語。

  例如，如果您的術語檔案包含以下英文到法文的項目：

  `EN: order, FR: commande` （根據英文 "to order" 翻譯為法文 "mander")。

  Amazon Translate 在翻譯下列句子時不會使用此項目，因為翻譯內容不相符：

  「**為了**讓我們協助您，請分享您的名稱。」 

  避免這種情況的建議：
  + 請確定每種語言的目標術語在語意上等於來源術語。
  + 避免具有多個意義的來源或目標術語。