gpt4 book ai didi

javascript - Google 翻译 API 未翻译 HTML 标记内的某些单词

转载 作者:行者123 更新时间:2023-12-02 22:45:02 25 4
gpt4 key购买 nike

我正在使用谷歌翻译 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"
};

最佳答案

编辑:问题出在类型上,我需要的是“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"
};

关于javascript - Google 翻译 API 未翻译 HTML 标记内的某些单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58437036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com