题意:"Google Cloud 翻译 JSON 文件"
问题背景:
I would like to translate the fields of a composite JSON object using Google Cloud Platform, instead of translating every single sentence on its own. Is it possible?
"我想使用 Google Cloud Platform 翻译一个复合 JSON 对象的字段,而不是单独翻译每一句话。这样做有可能吗?"
Example (from English to Italian):
"示例(从英语到意大利语):"
Origin JSON file:
{job_description: {
name: "Taxi driver",
description: "like the movie"
}
}
Output JSON file:
{job_description: {
name: "Tassista",
description: "Come nel film"
}
}
问题解决:
Translation API accepts only plain-text or HTML as a format [1].
"翻译 API 仅接受纯文本或 HTML 格式 [1]。"
To achieve your goal, load your JSON file as an object in your code, send the fields to the Translation API, edit the object with the translation result and then generate a JSON file from your new object.
"为了实现你的目标,将你的 JSON 文件加载为代码中的对象,将字段发送到翻译 API,使用翻译结果编辑对象,然后从新的对象生成 JSON 文件。"