Customize link button in textarea toolbar

I’ve connected to Google’s translation API and am translating pages via a button in the panel. The only problem is, kirbytext also gets translated, like (link:... text:...), (mail:...) and (tel...). When these words are translated, the kirbytext tags don’t work anymore, obviously.

I’ve created custom tags that work in all of my languages, so now I client can write (r:... t:...) for link/text, (m:...) for mail and (t:...) for tel, and therefore fail. Everything works fine when writing kirbytags by hand, but when I use the link button, of course, it goes back to inserting (link:... text...), etc.

Is there a way to extend or customize the link button in the textarea toolbar to add my custom kirbytags like (r:... t:...) instead of the default (link:... text:...)? Then my translations will correctly add links.

I’ve looked at the existing Enhanced Toolbar Link plugin, but thought there should be a simpler way for this case.

Wouldn’t it make more sense to ignore tags when translating?

It would, but it doesn’t seem like the Google translate API has an ignore feature unless you have a span with a “notranslate” class. (I’m sending the markup to the translator in kirbytext in the panel, which isn’t converted to HTML yet.)

I would assume that with a little bit of regex voodoo, it should be possible to put in those spans before sending the data to the API and then remove them again before displaying the translated results.

You’re right! I was able to add the span with regex, but unfortunately the span with “notranslate” class is being translated on Google’s side anyway. With Spanish, I send

<span class="no-translate">link:</span>

and get this back:

<abarcan clase = "notranslate"> enlace: </span>

Too bad.

EDIT:
With your regex idea, I was able to convert link: to r:, text: to t:, email: to m: and tel: to t:. Now, although Google Translate won’t ignore it, it translates to same letter in the other languages so I can use my custom Kirbytags to change to links etc on front end. Thanks for guiding me here :blush:

:crazy_face: