【问题标题】:Google translate API not translating some words within HTML tagGoogle 翻译 API 未翻译 HTML 标记中的某些单词
【发布时间】:2019-10-17 16:25:36
【问题描述】:

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

【问题讨论】:

    标签: javascript reactjs google-translate


    【解决方案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"
      };
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多