Google Cloud 翻译 JSON 文件

And*_*ppi 6 javascript php json google-cloud-platform

我想使用 Google Cloud Platform 翻译复合 JSON 对象的字段,而不是单独翻译每个句子。是否可以?

示例(从英语到意大利语):

原始 JSON 文件:

{job_description: {
    name: "Taxi driver",
    description: "like the movie"
    }
}
Run Code Online (Sandbox Code Playgroud)

输出 JSON 文件:

{job_description: {
    name: "Tassista",
    description: "Come nel film"
    }
}
Run Code Online (Sandbox Code Playgroud)

Yur*_*rci 1

翻译 API 仅接受纯文本或 HTML 作为格式[1]

为了实现您的目标,请将 JSON 文件作为对象加载到代码中,将字段发送到翻译 API,使用翻译结果编辑对象,然后从新对象生成 JSON 文件。