Google cloud platform 如何使用google cloud translate v3翻译长文本
环境: API:Google云翻译V3, 文本大小:12000字 通过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": [
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."]
}