Text API删除了不间断的空间

时间:2017-11-08 13:15:30

标签: microsoft-translator

我正在使用Microsoft Translator Text API来翻译网页的各个部分。我们使用的平台,在HTML中插入 以呈现空行。所以网页的一部分可以是:

<p>
  <span>This is a dummy text</span>
</p>
<p>
  <span>&nbsp;</span>
</p>

当我将其发送到Microsoft Translator Text API时,它会返回以下HTML:

<p>
  <span>Il s’agit d’un texte factice</span>
</p>
<p>
  <span></span>
</p>

我已将内容类型设置为text / html,并转义HTML字符以便能够将其发送到API(因此&nbsp;将替换为&amp;nbsp;)。但API返回的文本已完全丢失&nbsp;

如何阻止API删除HTML中的&nbsp;个实例?或者这是API中的错误吗?

2 个答案:

答案 0 :(得分:1)

notranslate span可能有助于防止翻译。您必须尝试查看它是否确实保留了nbsp标记。

答案 1 :(得分:1)

See the answer to Microsoft Translator API - notranslate trimming leading space? from Chis Wendt (Microsoft):

Translator trims leading and trailing space, and compresses any other white space to a single space. This is by design. Translator needs to move the words around freely to form the newly composed sentence, and wouldn't know what to do with the extra white space. A workaround would be to trim in your code before translation, and then restore the trimmed off pieces afterwards, depending on the context.

Line breaks and non-breaking spaces tend to be used for specific line layout based on the particular source text that would need to be laid out differently in another language in any case because of different word lengths and arrangements of the significant words.