Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: After translation html tags are turned to markdown #316

Open
bobkataboo opened this issue Sep 22, 2023 · 6 comments
Open

[BUG]: After translation html tags are turned to markdown #316

bobkataboo opened this issue Sep 22, 2023 · 6 comments
Milestone

Comments

@bobkataboo
Copy link

bobkataboo commented Sep 22, 2023

Describe the bug
I am using strapi-provider-translate-deepl. After running the translations my html

<h2 id="1">
text
</h2>

is turned to markdown

## text

Expected behavior

<h2 id="1">
text
</h2>

remains html after translation

Plugin config
Please add your plugin config here, e.g.

module.exports = {
  translate: {
    enabled: true,
    config: {
      // Choose one of the available providers
      provider: "deepl",
      // Pass credentials and other options to the provider
      providerOptions: {
        // your API key - required and wil cause errors if not provided
        apiKey: env("DEEPL_API_KEY"),
        // use custom api url - optional
        tagHandling: "html",
        apiUrl: "https://api-free.deepl.com",
        // use custom locale mapping (for example 'en' locale is deprecated so need to choose between 'EN-GB' and 'EN-US')
        localeMap: {
          // use uppercase here!
          EN: "EN-US",
        },
        translatedFieldTypes: [
          "string",
          { type: "text", format: "plain" },
          { type: "richtext", format: "markdown" },
          "component",
          "dynamiczone",
        ],
        apiOptions: {
          // see <https://github.com/DeepLcom/deepl-node#text-translation-options> for supported options.
          // note that tagHandling Mode cannot be set this way.
          // use with caution, as non-default values may break translation of markdown
          tagHandling: "html",
          formality: "default",
          // ...
        },
      },
      // other options ...
    },
  },
}
@bobkataboo
Copy link
Author

Please help me <3
I need this as it's stopping the releasing of our new websites

@sargreal
Copy link
Member

Hi @bobkataboo and thank you for opening this issue!

As we are working voluntary here, we cannot provide you with a time frame on when we can fix this.

Also, because showdown, the tool we use currently to achieve the translation of markdown by translating the markdown to html and back, does not support this, it is not a trivial fix.

The easiest workaround for now could be to enable some kind of automatic id generation in your markdown to html converter in the frontend.

@maxmaster82
Copy link

maxmaster82 commented Nov 14, 2024

bobkataboo { type: "richtext", format: "markdown" }, change to { type: "richtext", format: "html" }

@sargreal sargreal added this to the backlog milestone Nov 22, 2024
@JensUweB
Copy link

JensUweB commented Nov 28, 2024

Hi @bobkataboo and thank you for opening this issue!

As we are working voluntary here, we cannot provide you with a time frame on when we can fix this.

Also, because showdown, the tool we use currently to achieve the translation of markdown by translating the markdown to html and back, does not support this, it is not a trivial fix.

The easiest workaround for now could be to enable some kind of automatic id generation in your markdown to html converter in the frontend.

I'm not sure why you're talking about converting markdown to html here? The problem (if I understand him correctly) is that the field originally already contained html and got converted to markdown for no apparent reason by this plugin.

Let me add our use case to this:
We're using CKEditor 5 as richtext editor, not the default one. Every formatted string is saved as html by CKEditor, not markdown. When I translate a page that contains an CKEditor field, it gets transformed to markdown.

In my opinion this plugin should not do any transformation in fields that already contain html and just send the unmodified string to the provider (DeepL in our case). When I paste an html string manually into DeepL it translates it without problems & preverves the original html structure. You even suggested sending html to DeepL yourself in this post.

@sargreal
Copy link
Member

Dear @JensUweB,

You are completely right with your points there.

If you use the CKEditor plugin, you need to set the format of the rich text appropriately:

//…
        translatedFieldTypes: [
          "string",
          { type: "text", format: "plain" },
          // rich text is html with CKEditor
          { type: "richtext", format: "html" },
          "component",
          "dynamiczone",
        ],

The reason why I talked about the conversion is, that I was under the impression, that in the original issue, the actual richtext format was markdown (because of the given config). Only some parts in the markdown were html (like in this case the heading with a specific id), which cannot be transformed reliably by this plugin.

@JensUweB
Copy link

@sargreal Oh my...I'm just a bit stupid, sorry! The error in my case was, that the translateFieldTypes option was in the wrong spot. I accidentally put it into providerOptions. No wonder it wasn't working. 😅
Now translating html works as expected for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants