我正在使用谷歌翻译API,并且我注意到,在翻译HTML时,有时会丢失标记内的单词,并以英语返回原始单词,例如:
发送后:
"<div>
<span id=0>you</span> <span id=1>youth</span> <span id=2>young</span> <span id=3>your</span>
<span id=4>yourself</span> <span id=5>youtube</span> <span id=6>youngster</span> <span id=7>yours</span> <span id=8>youse</span> <span id=9>youthful</span>
</div>"
我找回了一个未翻译的跨度,而其他未翻译:
<div>
<div> <span id = 0> אתה </span> <span id = 1> youth </span> <span id = 2> צעיר </ span> ...
</div>
有没有一种方法可以强制翻译HTML标记?
编辑:类型有问题,我需要的是'text / html'
const request = {
parent: translationClient.locationPath(projectId, location),
contents: [textToTranslate],
mimeType: "text/html", // mime types: text/plain, text/html
sourceLanguageCode: "en-US",
targetLanguageCode: "he"
};
答案 0 :(得分:1)
编辑:问题出在类型上,我需要的是'text / html'
const request = {
parent: translationClient.locationPath(projectId, location),
contents: [textToTranslate],
mimeType: "text/html", // mime types: text/plain, text/html
sourceLanguageCode: "en-US",
targetLanguageCode: "he"
};