DeepL Application

Last modified by Admin on 2025/03/01 00:13

cogTools to translate content in XWiki using DeepL
TypeXAR
CategoryApplication
Developed by

Clément Aubin

Active Installs0
Rating
1 Votes
LicenseGNU Lesser General Public License 2.1
Success

Installable with the Extension Manager

Description

The DeepL application provides a couple of tools to help translate wiki content to DeepL.

Warning

This extension is now obsoleted by the Machine Translation Application.

Please note that this application will only work if your wiki is set to be multilingual.

Configuration

With the extension installed, you will first need to add the following keys to xwiki.properties in order to set your API key and the DeepL API domain to use :

deepl.api.key=YOUR_API_KEY
deepl.api.domain=YOUR_DOMAIN

The value of deepl.api.domain can be either https://api-free.deepl.com or https://api.deepl.com depending if you are using the free tier of DeepL or if you have a paying subscription.

Once these parameters are set, restart the wiki for them to go into effect. After XWiki has restarted, you can verify that the integration is working by going to the page DeepL.Code.DeepLUsage, which will show the number of characters that you have used for DeepL translations.

DeepL Translation Macro

This application provides a macro which will display a link to some page content to the browser language through DeepL.

The macro ID is deeplTranslation. Once the extension is installed, head to DeepL.Code.DeepLTranslationMacro for a usage example.

ParameterMandatoryDescriptionDefault value
cssSelectorYesIndicate which CSS block should be translated.N/A
classSelectorNoAllows to only display the translation link if the current page has at least one object of the class specified in classSelector. If the parameter is empty, no restriction gets applied.N/A
extraCssClassesNoAdditional CSS classes to be added to the translation link.N/A

Translating comments

The application will expose a configuration in the wiki administration, in the section "Content" > "DeepL", allowing to enable or disable the display of translation links on comments in documents. By default, this feature is disabled.

Note that as XWiki does not store the language of each comment, we cannot determine if a comment is written in the same language as the page in which it stands, thus, this feature will add translation links under each comment, regardless of its language.

Javascript API

The application also provides a Javascript API to dynamically add new translation links in pages. This API can be reached through RequireJS and is defined in DeepL.Code.DeepLTranslationJSX. Below is an example of code used to add translation links to comments, used in DeepL.Code.DeepLCommentTranslation :

require.config({
  paths: {
   'deepl-translation': "${escapetool.javascript($xwiki.getURL('DeepL.Code.DeepLTranslationJSX', 'jsx', "language=$!{xcontext.language}"))}"
  }
});

require(['jquery', 'deepl-translation'], function($, api) {
 if (api.needTranslation()) {
    (XWiki && XWiki.domIsLoaded && loadComments()) || document.observe("xwiki:docextra:loaded", function(event) {
     if (event["id"] = "Comments") {
        loadComments();
      }
    });
  }

 function loadComments() {
    $('.xwikicomment').each(function(index, value) {
     let elem = $(value);
     let link = api.createTranslationLink('#' + elem.attr('id') + ' .commentcontent');
      elem.append(link);
      api.registerTranslationLink(link);
    });
  }
});

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.2.1

v1.2

v1.1

Get Connected