Nucleus
Ecosystem

Native spell check

Check spelling in a Kotlin desktop app with PlatformSpellCheckerKt, a wrapper over each operating system's native spell-check engine.

PlatformSpellCheckerKt lets you check spelling from Kotlin using each operating system's native spell-check engine. Nucleus does not ship a spell-check module; this library already covers the platforms Nucleus targets, so add it to your app directly.

Add the dependency

build.gradle.kts
dependencies {
    implementation("com.darkrockstudios:platform-spellcheckerkt:<version>")
}

Check spelling

Create a checker through PlatformSpellCheckerFactory, then check either a single word or a whole string:

val checker = PlatformSpellCheckerFactory().createSpellChecker()

// Check a single word; the result carries suggested corrections.
val result = checker.checkWord("sentance")
val suggestions = result.suggestions // e.g. ["sentence", ...]

// Check a full string; each entry reports the misspelled word and its position.
val misspellings = checker.checkMultiword("This is a sentance with errors")
// each entry: misspelledWord, startIndex, length

checkWord validates one token and returns its suggestions. checkMultiword scans a string and returns one entry per misspelling, each with the word and its offset in the text.

How it works

The library delegates to the spell-check engine already built into the host OS:

  • macOSNSSpellChecker, the same engine TextEdit and the system text fields use.
  • Windows — the Windows Spell Checking API (available since Windows 8), through the ISpellCheckerFactory COM interface.
  • Linuxhunspell.

Because it uses the platform engine, spelling behavior, installed dictionaries, and language detection match what the user already sees elsewhere on their system.

Notes

On Linux, spell checking depends on hunspell. Install it through your distribution's package manager; if it is missing, the checker cannot run.

What's next