【AWS CLI 示例集】Translate

Translate

我们主要检查是否可以使用AWS Cloud9执行命令。
如果您想提供示例命令,请使用下面的表格提交。
如果列出的命令示例有任何错误,请在此处更正。

建议
建议内容可能会被修改。在提出任何建议之前请注意这一点。


确定文本的语言

text="Time is money"
aws comprehend detect-dominant-language \
--text "$text"

输出

{
    "Languages": [
        {
            "LanguageCode": "en",
            "Score": 0.9972456693649292
        }
    ]
}

by ton

确定文本语言并翻译成中文

text="Time is money"
lang=$(aws comprehend detect-dominant-language \
--text "$text" \
--query 'Languages[0].LanguageCode' \
--output text)
aws translate translate-text \
--source-language-code $lang \
--target-language-code "zh" \
--text "$text" \
--query 'TranslatedText'

输出

"时间就是金钱"

by ton


对 S3 存储桶中的 Excel 文件运行翻译作业

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 it \
--job-name my-translation-job

输出

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

by anonymous

检查工作状态

aws translate describe-text-translation-job \
--job-id 4446f95f20c88a4b347449d3671fbe3d

输出

{
    "TextTranslationJobProperties": {
        "JobId": "4446f95f20c88a4b347449d3671fbe3d",
        "JobName": "my-translation-job",
        "JobStatus": "COMPLETED",
        "JobDetails": {
            "TranslatedDocumentsCount": 0,
            "DocumentsWithErrorsCount": 0,
            "InputDocumentsCount": 1
        },
        "SourceLanguageCode": "en",
        "TargetLanguageCodes": [
            "es", 
            "it" 
        ],
        "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"
    }
}

by anonymous

タイトルとURLをコピーしました