A Kotlin Multiplatform wrapper around different platform's native spell checker systems.
  • Kotlin 97%
  • Swift 2.5%
  • Shell 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
adam 123379e824
Compile the desktop target against the JDK 17 API
Locale.of does not exist in JDK 17, so the previous commit broke the build on
CI. Pass -Xjdk-release to match the JVM 17 target, which also makes the Locale
constructors non-deprecated again.
2026-11-22 14:00:07 -08:00
.github/workflows Update maven-publish to 0.37.0 and migrate to KMP Android library plugin 2026-08-03 22:18:17 -07:00
androidApp Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
docs Add Dokka API docs and gh-pages deploy workflow 2026-06-28 19:02:11 -07:00
exampleApp Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
gradle Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
iosApp Upgrade to AGP 9.4.1, Kotlin 2.4.21, Compose Multiplatform 1.12.2, Gradle 9.8.1 2026-10-17 16:02:08 -07:00
PlatformSpellChecker Compile the desktop target against the JDK 17 API 2026-11-22 14:00:07 -08:00
.gitignore Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
build.gradle.kts Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
CLAUDE.md Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
gradle.properties Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00
gradlew Upgrade to AGP 9.4.1, Kotlin 2.4.21, Compose Multiplatform 1.12.2, Gradle 9.8.1 2026-10-17 16:02:08 -07:00
gradlew.bat Upgrade to AGP 9.4.1, Kotlin 2.4.21, Compose Multiplatform 1.12.2, Gradle 9.8.1 2026-10-17 16:02:08 -07:00
LICENSE Prepare for publishing 2025-11-28 21:48:18 -08:00
README.md Search DICPATH for Hunspell dictionaries on Linux 2026-10-17 15:50:39 -07:00
settings.gradle.kts Fix deprecation warnings across the build 2026-11-22 13:47:17 -08:00

Platform Spell Checker Kt

CI Maven Central License API Docs

KMP badge-jvm badge-android badge-ios

This Kotlin Multiplatform library wraps the OS's native spell checker on each supported platform. It then provides a Kotlin friendly API.

The big advantage here is that nothing needs to be bundled with your program. Especially dictionaries. Most likely, what ever the user's language is, they will already have the proper dictionary on their device for the system level Spell Checker.

Note: Each platform can and will give different results for the same word. This library does not attempt to correct these results.

Documentation

Full API reference and recipes: darkrock-studios.github.io/PlatformSpellCheckerKt.

Dependency

implementation("com.darkrockstudios:platform-spellcheckerkt:1.0.0")

Usage

Create a Spell Checker

// Android's PlatformSpellCheckerFactory requires a context, thus you will need to construct it
// in platform-specific code and pass it down into common code.
val factory = PlatformSpellCheckerFactory(context)
val factory = PlatformSpellCheckerFactory()

// Use the user's current/system language
val checkerDefault = factory.createSpellChecker()

// Or request a specific locale (validated). Country is optional.
val checkerUkUa = factory.createSpellChecker(SpLocale.UK_UA)

// Check before you create! Creating a Spell Checker for a locale that isn't supported will throw an exception
if (factory.hasLanguage(SpLocale.EN_GB)) {
    val gbChecker = factory.createSpellChecker(SpLocale.EN_GB)
}

// You can also create a checker manually
val checker = PlatformSpellChecker(SpLocale.EN_US)

Use a Spell Checker

// Check a single word for spelling errors
val result = checker.checkWord("mispelledWord")
if (isMisspelled(result)) {
	result.suggestions.forEach { println(it) }
}

// Sentence level correct is also supported
val misspellings = checker.checkMultiword("This is a sentence with a mispelled word.")
misspellings.forEach { println("${it.misspelledWord} at ${it.startIndex} with length ${it.length}") }

Utilities

val factory = PlatformSpellCheckerFactory()

// Is a spell checker available on this platform at runtime?
val available = factory.isAvailable()

// What locale does the system currently use?
val systemLocale: SpLocale = factory.currentSystemLocale()

// A best-effort list of available Spell Checker locales on this device
val locales: List<SpLocale> = factory.availableLocales()

Logging

Spell check calls fail open. If the platform provider is unavailable, does not respond within the operation timeout, or returns something malformed, the check degrades to "correctly spelled" rather than throwing. This keeps a flaky system service from crashing your app, but it also means a broken provider looks exactly like a document with no typos.

Every one of those paths logs a warning through Napier, which discards logs until a base is installed. Install one during startup or you will get no warning at all:

import io.github.aakira.napier.DebugAntilog
import io.github.aakira.napier.Napier

Napier.base(DebugAntilog())

Worth knowing when something reports no spelling errors for anything: Android emulator images often have a spell checker service that binds but never responds, so every check hits the timeout. With logging installed that shows up as:

W PlatformSpellChecker$checkWord: checkWord('boooks') timed out after 3s
  — spell-checker provider did not respond

Test on a physical device before concluding the library is at fault.

Supported Platforms

Platform Supported Implementation Details
Android ✅ Wraps TextServicesManager's SpellCheckerSession with full featured support.
iOS ✅ Wraps UITextChecker for full featured support.
JVM - Windows ✅ Wraps the Win32 API COM Object for ISpellCheckerFactory for full featured support.
JVM - Linux ✅ Linux has no native spell checker API, so this library looks to see if hunspell is installed, and uses it, otherwise it reports Spell Checking is not supported. Single word spell checking is a first class citizen, but sentence level correct is really just decomposing the sentence into individual single word checks, so is not as robust as other platforms. Dictionaries are looked up in the directories listed in DICPATH (colon separated), then in the standard system paths.
JVM - macOS ⚠️ Wraps NSSpellChecker for partial support.
Known issues:
• There is an issue with JNA calling into certain platform APIs, so sentence level correct is hacked together right now.
• MacOS has a bit of a weird spell checker, the words it considers "correct" are not always what I would expect, but who am I to question the wisdom of Tim Apple.
K/N - Winx86 ❓ Support is certainly possible, but there aren't any examples I've found for binding COM objects in K/N, so would take some exploration.
WASM-JS ❌ Can't work I don't think because there is no standard browser spell checker API as far as I have found.