【发布时间】:2019-12-29 12:04:56
【问题描述】:
https://api.cognitive.microsofttranslator.com/translate?api-version=3.0
我正在使用 Microsoft 文本翻译器将 html 内容翻译成其他语言。由于此 API 一次只能处理 5000 个字符,因此我使用 Python 将大型 Html 内容转换为大约 5k 个字符的数据块,而不会将 html 标签分成两半。
我在使用拆分的每个块调用 API 时遇到以下问题。
当我在参数部分使用“plain”作为 textType 时,它甚至会翻译元标记信息(如 Hello 到葡萄牙语的 Olá),这会导致在处理大型 Html 内容时出现格式问题。
当我在参数部分中使用“html”作为 textType 时,它不会像上面那样翻译 html 元标记信息,但是它的 自动关闭在每个块中打开的块末尾的标签。这再次导致格式问题。
示例:(出于此示例的目的,我为每 5 行分块)
<html>
<body>
<table>
<tr>
<td>ENAME</td>
<td>ENO</td>
<td>DEPTNO</td>
</tr>
<tr>
<td>Bob</td>
<td>121</td>
<td>300</td>
</tr>
<tr>
<td>Aron</td>
<td>122</td>
<td>302</td></tr>
</table>
</body>
</html>```
Chunk1: <html><body><table><tr><td>ENAME</td>
chunk2: <td>ENO</td><td>DEPTNO</td></tr><tr><td>Bob</td>
chunk3: <td>121</td><td>300</td></tr><tr><td>Aron</td>
chunk4: <td>122</td><td>302</td></tr></table></body></html>
I call API with each chunk and translate it into required language and in the end I concatanate all responses of all chunks(which will give the total translated html content).
chunk 1 processing
--------------------
<html><body><table><tr><td>ENAME</td>
when I pass above string to API bleow response I am receiving
<html><body><table><tr><td>Ename</td></tr></table></body></html>
It's automatically closing the tr,table,body and html which is not at all my intention, as it will be closed 4th chunk when I call API with it.
As it's automatically closes the tags in the first chunk itself instead of waiting till 4th chunk, resulting the formatting issue.
Could you please let me know how to hanlde this issue without having formatting issues.
Looking forward for the fast response!!
Thank you!!
【问题讨论】:
标签: python-3.x microsoft-translator