OwO-Network/DeepLX

Feature: support "tag_handling": "html"

Closed this issue · 7 comments

To translate text with HTML tags, such as:

<p>The Four Laws are: </p>\n\n<ul>\n<li><strong>Make it obvious</strong></li>\n<li><strong>Make it attractive</strong></li>\n</ul>\n\n<p>These are based on the four steps of the habit loop: cue, craving, response, and reward.</p>\n

https://www.deepl.com/docs-api/translate-text/translate-text

If you want to implement this feature, you are welcome to submit a PR. Because this project is based on the DeepL iOS App, this feature is currently not supported.

I am not familiar with how to compile and test this library. Here are a few tips we may try:

  1. Add the tag_handling somewhere in translateByAPI, it should be in the payload.

The https://api-free.deepl.com/v2/translate supports the "tag_handling": "html" based on an API call to DeepL.

It should be able to handle HTML tags, and there is no need to try step 2.

  1. Add an option for Splitting: nonewlines (default when tag_handling=html) - splits on punctuation only, ignoring newlines.

It's the code in this lib:

Params: Params{
			Splitting: "newlines",
...
}

Please note: These are two completely different APIs, and I am not sure if the Splitting parameter is available in the same way.

I verified the https://api-free.deepl.com/v2 support "tag_handling": "html" with a direct API call to the URL. (with other program language). It will return the correct result with HTML tags.

I assume https://www2.deepl.com supports it as well, but I didn't verify that.

You can Fork this project and modify it to try.

I just tried on the JS one: https://github.com/ifyour/deeplx. I make two lines of change, and it works.

  1. Remove the splitting param.
  2. Add tag_handling.

Screenshot 2024-01-01 at 12 16 39 PM

The translate result before the modify:

<ul\n<li><strong>

After the modify:

<ul> <li><strong>

Just a reference if you are willing to try it. Thanks.

I don't know how to add this feature, as it is a niche requirement.

Maybe I will add it in the next version, please stay tuned.