Machine translation in Collabora Online and Collabora Office 26.04.6: any provider, your own settings, and an open source option

Writer has had a Translate command for a while: pick a language, and the selection or the whole document is replaced by its translation, paragraph by paragraph, with the formatting kept. Until now it had exactly one back end, DeepL, and only an administrator could set it up. Collabora Online 26.04.6 turns that into a provider framework, adds LibreTranslate as a second provider, lets users set up a provider of their own in the Options dialog, and brings the feature to Collabora Office, the desktop application, where it did not work at all. This post walks through what changed and how it is built.

What we had

The Translate command lived in Writer alone and was wired to DeepL by name. The engine had a single function that posted the HTML of a paragraph to the DeepL API with the key in the Authorization header, and the Writer helper read the DeepL settings from the engine configuration, two keys under Linguistic/Translation/Deepl, before calling it.

Those two keys came from the server: coolwsd.xml had a deepl block with enabled, api_url and auth_key, coolwsd exported the URL and the key into the environment of the document process, and the engine wrote them into its configuration at start. The enabled switch did nothing but show or hide the menu entry in the browser.

Nothing of this was visible to a user. There was no section in the Options dialog, unlike the AI assistant and the remote sentence checkers, so a personal DeepL key had nowhere to go. Collabora Office, which has no coolwsd.xml, had no way to configure DeepL at all, and its web UI never showed the command. Worse, the desktop app exported two empty strings into the environment, which the engine wrote over whatever its configuration held.

Just before this work, three smaller changes had already landed: the language list is asked from DeepL’s own API instead of a hard-coded list of 28, the list is searchable, and translated text gets the language attribute of its target, so spell checking and hyphenation work on it. The provider framework builds on those.

Providers in the engine

The engine side is a small interface in the linguistic library, plain C++ rather than a new UNO service:

				
					class TranslationProvider
{
public:
    virtual OString getId() const = 0; // "deepl", "libretranslate"
    virtual OUString getDisplayName() const = 0;
    virtual bool isEnabled() const = 0;
    virtual bool isConfigured() const = 0;
    virtual TranslateResult translate(const OString& rHtml,
                                      const OString& rTargetLang,
                                      const bool& rCancel) = 0;
    std::vector<OString> getTargetLanguages(bool bAskService = true);
};
				
			

A provider translates an HTML fragment to a BCP 47 language tag and lists the languages its service can translate into. The list is asked once per configuration and kept; after a failed request the service is left alone for five minutes, so a server that is down does not stall every open of the dialog. Providers read the configuration on every call, never caching it: a user’s own settings arrive after the process has started.

A registry holds the providers in a fixed order, and a new setting, Linguistic/Translation/Provider, picks one. Empty means the first provider that is enabled and set up. A provider named explicitly but not set up means no translation, never a silent swap for another one. The configuration schema gained a group per provider: DeepL keeps its ApiURL and AuthKey and gains IsEnabled, on by default so an existing setup keeps working; LibreTranslate has BaseURL, ApiKey, IsEnabled and SSLCertVerify.

The Writer helper now asks the registry for the active provider and hands it each paragraph. The dialog passes language tags through as they are; each provider spells them the way its service wants, DeepL in uppercase, LibreTranslate by the codes its server lists. The curl-specific build guards in Writer went away with that: the registry always exists, and a build without curl simply has no provider.

LibreTranslate

LibreTranslate is a self-hosted machine translation API under the AGPL, built on the Argos Translate models. The provider posts a JSON document to the /translate endpoint of the configured server root, with the source language left to the server to detect, the html format so the markup survives, and the api_key member only where a key is set, since a self-hosted server usually needs none. The language list is the union of every source’s targets from /languages. The server’s own codes are kept from that list and used when translating, which matters for traditional Chinese: the server calls it zt, the rest of the world zh-Hant.

A self-hosted server translates on its CPU, so a long paragraph can take seconds; the provider allows 30 seconds per request where DeepL gets 10. A pasted translate endpoint is taken for the root, and a certificate check can be switched off for test setups, as for the checkers.

Running a server next to Collabora Online is documented in docker/libretranslate, in the shape of the Grammalecte and LanguageTool recipes. The Dockerfile installs the pinned release from PyPI with every package checked against a hash, fetches the models of a chosen language list into the image at build time, and runs the server as an unprivileged user with the web UI and file translation switched off. Every model goes to or from English, so a translation between two other languages pivots through English, and a build needs at least two languages. The image holds the language packages and the sentence boundary models alike, so the container runs with no network at all, which is how compose.yaml runs it: on an internal network beside the collabora/code image, with the provider switched on through extra_params. The README covers requiring an API key for a server that must be reachable more widely.

Configuration on the server, and none in the desktop app

coolwsd.xml gained a translation block with the provider choice and a libretranslate block next to deepl; both provider blocks have an allow_user_settings switch, off by default, as the checker blocks do. coolwsd exports all of it into the document process’s environment the way it exports the checker settings, inside the server-only part of the code. That is also the fix for the desktop app: it exports nothing, so a user’s own settings stand.

In the kit, a new module mirrors the one that handles the remote checkers. It writes the server’s settings into the engine configuration from the environment, and where the environment says nothing, as in the desktop app, the schema’s defaults. It answers a new command, .uno:TranslationProviders, with what the settings dialog needs to know: which provider is asked for, which one translates, and for each provider whether it is enabled and set up, its server, and whether a key is stored. The key itself never leaves the kit; the dialog learns only that there is one.

The browser’s switch for showing the command changed with it. Before, only the server’s deepl.enabled decided. Now any enabled provider does, and the desktop app shows the entry unconditionally, leaving it to the engine to say whether a provider is set up.

Your own settings

The Translation section of the Options dialog, with a LibreTranslate server being set up.

The Options dialog gained a Translation section. It offers the choice of provider and a panel per provider, with an Enabled switch, the server URL, the key, and the certificate check for LibreTranslate. A stored key is shown as a masked placeholder, never as text. Which fields may be edited follows the rule the checkers set: in the desktop app always, on a server only where the administrator allowed user settings for that provider. A provider the server switched off is not offered at all.

The settings travel the way the checkers’ settings do: the dialog writes them into the user’s document settings file, which reaches the kit as the settings are applied, filtered by an allow-list. The provider choice is always allowed; a provider’s group only where the server permits it. The whole Translation subtree is excluded from what goes back to the host, so a key is applied but never uploaded.

Once saved, the section says which provider translates. The Reset button puts a panel back to the server's settings.

Each panel, and the provider choice, has a Reset button. Clearing a field would have meant an empty server, which switches the provider off; Reset instead drops the user’s own values, so the server’s apply again, or the defaults in the desktop app. To make that true in the running process and not just in the file, the kit re-reads the server’s settings before it applies the user’s when a user re-reads their own settings alone on a document, through a new variant of the settings message. A view joining a shared document only lays its own settings over what is in force, as the others’ settings are not its to drop.

The kit also reports, next to the values in force, what the server set up. A reset panel is rebuilt from those at once, so the user sees what will apply before saving. The same button and the same mechanics were given to the remote checker panels, and the checker bridge in the kit was taught to restore the schema defaults where the server sets nothing, which it had not done before; a checker’s own choices, the Duden style checks and the Grammalecte rule families, are left alone by Reset, as they are the user’s and not the server’s.

A command that is there only when it works

The Translate button on the Review tab, shown because a provider is set up.

The engine always disabled the Translate command when no provider was configured, but the browser never heard about it: the command was missing from the table of commands whose state the kit reports. It is in that table now, and after a user’s settings are applied the kit invalidates the command in every view, so the state is sent anew. The notebookbar button hides while the command is disabled, the way the Ungroup button does; the classic menu entries got the same option, and the phone menu honours it too. The result is that the button appears the moment a provider is set up in the dialog, without reopening the document, and is absent while none is.

The language list comes from the provider's own server: here the two languages a small test image was built with.
The document after a translation to German, with the language of the text set to German as well.

Shared plumbing

Two cleanups fell out of the work. The remote sentence checkers had a curl wrapper of their own in lingucomponent, and the translation providers had grown a second one. There is one now, in the linguistic library that both link: a Request, a Response, post(), get(), percent encoding and JSON parsing. It reads the body of an error answer, which the translators want for the service’s message, so a failed request is told by a flag and a text rather than a curl code; the checkers’ libraries no longer depend on curl themselves.

The tests of the checkers and the translators had four small HTTP servers between them, each on a thread of its own. unotest now has one, which takes a port and a handler, reads each request as far as its Content-Length says, and keeps every request for the test to inspect by method, path, headers and body. Each test makes its own.

How it was verified

Every layer has a unit test: the providers against the mock server, the Writer helper end to end with a mock DeepL, the kit’s command values, and the checker protocols over the shared HTTP code. Beyond that, the whole chain was driven through the web UI over the DevTools protocol, in Collabora Online against a local coolwsd and in Collabora Office against the real LibreTranslate container: settings saved, provider reported, dialog listing the server’s languages, document translated, Reset restoring the defaults. The container image was tested with the network switched off, which is how it caught that the sentence boundary models had been left behind in the build stage.

Writing this post found two faults in the Writer helper that predate the series. A heading was pasted back as a block element, which split it into a translated paragraph and an empty heading, and the extra node pushed the last paragraph of the document out of the range being translated. Pasted text also took the HTML import’s default paragraph style, so a title or a heading came back as body text. The helper now pastes headings inline, follows the end of the range as it moves, and puts the paragraph style back after the paste.

What is next

The design leaves room for a provider that runs in the browser, such as Bergamot, the project behind Firefox’s offline translation, or a browser’s own translation API: the engine would hand each paragraph to the client and wait for the answer. That is designed but not built. Two smaller items remain: the knowledge of which providers exist is spelled out in the kit, the allow-list and the dialog, where the provider interface could carry it, and the HTTP round trip could go through Collabora Online’s own asynchronous stack instead of blocking the document process on curl.