Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何使用google cloud translate v3翻译长文本_Google Cloud Platform_Google Cloud Translate - Fatal编程技术网

Google cloud platform 如何使用google cloud translate v3翻译长文本

Google cloud platform 如何使用google cloud translate v3翻译长文本,google-cloud-platform,google-cloud-translate,Google Cloud Platform,Google Cloud Translate,环境: API:Google云翻译V3, 文本大小:12000字 通过translateText()方法可以翻译单词和短句,但是当我运行整个文本时,会遇到“文本太长”错误 "message": "Text is too long.", "code": 3, "status": "INVALID_ARGUMENT", "details": [

环境: API:Google云翻译V3, 文本大小:12000字

通过
translateText()
方法可以翻译单词和短句,但是当我运行整个文本时,会遇到“文本太长”错误

"message": "Text is too long.",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": [
        {
            "@type": 0,
            "data": "type.googleapis.com\/google.rpc.BadRequest"
        },
        {
            "@type": 0,
            "data": [
                {
                    "field": "contents",
                    "description": "The total codepoints in the request must be less than 30720, actual: 90005"
                }
            ]
        }
    ]
}

U可以将文本分成多个部分(多个请求),在
contents[]
中最多包含30k个代码点,如API中所述:


或者使用批翻译,它在异步批处理模式下翻译大量文本:。这一个稍微复杂一点,因为你必须将文件上传到谷歌云存储中。

U可以将文本分成多个部分(多个请求),在
contents[]中最多有30k个代码点。
如API中所述:

或者使用批翻译,它在异步批处理模式下翻译大量文本:。这一个稍微复杂一点,因为你必须将你的文件上传到谷歌云存储

// Request 1
{
  "sourceLanguageCode": "en",
  "targetLanguageCode": "de",
  "contents": ["Text part one..."]
}

// Request 2
{
  "sourceLanguageCode": "en",
  "targetLanguageCode": "de",
  "contents": ["...text part two..."]
}

// Request n
{
  "sourceLanguageCode": "en",
  "targetLanguageCode": "de",
  "contents": ["...text part n."]
}