UlionTse / translators

🌏🌍🌎Translators🌎🌍🌏 is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python. Translators是一个旨在用Python为个人和学生带来免费、多样、愉快翻译的库。
https://pypi.org/project/translators/
GNU General Public License v3.0
1.62k stars 189 forks source link

[Bug]: translate_html strips whitespace #149

Closed gdillo closed 9 months ago

gdillo commented 9 months ago

Debug Tips

What happened?

Using .translate_html (with translator='google') returns HTML with leading and trailing whitespace removed from all tags.

casehtml = ts.translate_html(casehtml, translator='google')

Is there a way to preserve the whitespace?

APP Version

5.8.9

Python Version

3.11

Runtime Environment

Windows 10

Country/Region

UK

Relevant log output

No response

Screenshots

![DESCRIPTION](LINK.png)

Code of Conduct

UlionTse commented 9 months ago

@gdillo Hello friend. In order to solve your problem, we first need to figure out what causes the spaces to disappear. There are two reasons. The first is the preprocessing of the translated text. I did perform a strip operation in order to accurately count the length of the input text, avoid translation errors, and improve translation efficiency. The second is, that even if I don't preprocess the space strip, will the translation service itself perform the same processing, causing the translated text to be missing meaningless spaces? Therefore, it is recommended that you handle the issue of spaces separately from the translation service.