Andras Timar
More languages, from the system you already have
Collabora Office on Windows now spell checks languages it has no dictionary for, by asking Windows. The bundled dictionaries, 68 packages built on Hunspell, cover the languages most of our users write in, but not all of them. Finnish, Armenian, Georgian and Filipino are among the languages that have no usable Hunspell dictionary and that Windows checks perfectly well, through the Basic typing feature of a language pack. Until now a document in one of those languages got no red underlines at all. Now it gets the ones Windows would draw in any other application.
The new backend is a Windows-only service, cpo.lingu.WinSpellChecker, built on the Windows Spell Checking API that has been part of the system since Windows 8. There is nothing to install and nothing to configure. Add a language in Windows Settings, under Time and language, with its Basic typing feature, and Collabora Office checks it on the next start.
One backend per language
The interesting design question was not how to call the API but how to share languages with Hunspell. The engine’s spell checking dispatcher can chain several checkers for one language, and it accepts a word as soon as one of them does. That sounds generous and is in fact a loss: a Hunspell dictionary does not only list the words a language has, it also marks words that look right and are wrong, the forbidden words its maintainers curated over the years, and a second checker that accepts them would silently undo that work.
So the Windows backend never shares a language with Hunspell. When it is first asked which languages it serves, it takes the list Windows reports, drops every language that an installed Hunspell dictionary covers, and claims the rest. For any one language exactly one backend answers. A language added to Windows later, or a dictionary removed, shows up on the next start, which is how the Hunspell backend has always behaved too.
The same rule now applies on macOS and iOS. Those apps have used the system spell checker beside Hunspell for years, chained, so that a word passed if either accepted it. The system checker there now claims only the languages Hunspell does not cover, with the same helper the Windows backend uses: the code that enumerates the registered dictionaries and the languages they serve moved out of the Hunspell backend into the shared linguistic utilities, and all three backends call it.
How it works
The service holds one COM spell checker factory for the life of the process and creates a checker per language on first use, keeping it for the next word. A language Windows fails to create a checker for is remembered as such, so it is not asked again for every word. The whole thing lives in the COM apartment of the main thread, entered once when the languages are first read and left when the service goes away; every call comes in on that thread, which an assertion now checks.
Words go to Windows one at a time, through the API’s Check call, and suggestions come from Suggest. The API’s own Add, Ignore and AutoCorrect are not used: the user’s own dictionaries and ignore lists stay where they always were, in the engine, where they work the same for every backend. A correction that differs from the word only in case is reported as a capitalization error, the way the engine classifies it elsewhere, and the two options that mute errors on upper-case words and on words with digits apply here as they do to Hunspell.
A failing call counts as a correct word. If the Windows service is unavailable, or a checker cannot be created, or a call throws, nothing in the document turns red; the backend logs once and stays quiet. A dead service must never paint a document with false errors.
One protocol detail is worth a sentence. The Hunspell backend accepts special queries, wrapped in a small XML envelope, that add words at runtime; the dispatcher probes a checker for that ability by sending such a query. Windows has nothing to add words to, so the probe is answered with no and the query is never sent to Windows.
What it covers
Which languages the backend claims depends on the machine: the language packs installed in Windows, minus whatever a bundled dictionary covers. On a typical installation that means the languages Windows has and we do not, and nothing else. English, German, French and the other languages with a bundled dictionary continue to go to Hunspell, with the dictionaries’ curation intact.
A unit test on Windows checks the contract: the sets of languages the two backends claim are disjoint, and, on a machine whose English comes from Windows rather than from a Hunspell dictionary, Windows accepts “receive”, rejects “recieve” and offers suggestions for it.
Where to look
The backend is in the engine under lingucomponent, in spellcheck/winspell, next to the Hunspell and macOS backends. The shared helper that decides who covers which language is in lingutil. The service is registered like any other spell checker and needs no configuration entry: the linguistic service manager discovers it, asks it for its languages, and adds them to the lists the documents use.
The feature is available in Collabora Office 26.04.5 and higher.