Microsoft Translator Text API breaks notranslate spans

偶尔善良 提交于 2021-01-27 19:20:30

问题


I'm using the Microsoft Translator Text API to translate some sentences. My sentences contains some parts of text that I need to not being translated.

To achieve this I using <span class="notranslate"></span> by wrapping not translatable text. It works good in most cases, by in some cases MT API breaks this spans.

Examples (Input -> Output):

  • some <span class="notranslate">1</span> text -> деякий 1 текст

  • some <span class="notranslate">1</span> another text -> деякий <span class="notranslate">1 інший </span> текст

Good Example:

  • some <span class="notranslate">1</span> text -> деякий <span class="notranslate">1</span> текст

I do not observe any regularities, it happens randomly. Maybe I miss something?

UPD:

I tried to send headers Content-Type: text/xml or Content-Type: text/html - the same result in both: engine breaks some spans.


回答1:


I found the solution.

Microsoft Translator API 3.0 Documentation recommends to use <div class="notranslate"></div> instead of <span class="notranslate"></span>.

I use API 2 version, but seems like after changing wrapper to <div>, MT API stopped breaking of my notranslate wrappers.



来源:https://stackoverflow.com/questions/50128414/microsoft-translator-text-api-breaks-notranslate-spans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!