betto_lang_detector library

A pure-Dart language detection library for Dart and Flutter applications.

Detects language using a two-stage pipeline:

  1. A Unicode script pre-filter (near-free, resolves several languages outright).
  2. A character n-gram model (Cavnar & Trenkle "N-Gram-Based Text Categorization") disambiguating same-script languages.

Covers 58 languages, matching the betto_lexical package's Stopwords set. Zero runtime dependencies — no FFI, no native build, works identically on web, mobile, and desktop.

The single public entry point is LanguageDetector.

Example:

import 'package:betto_lang_detector/betto_lang_detector.dart';

final detector = LanguageDetector.pureDart();
final result = detector.detect('Bonjour le monde');
if (result case Detected(best: final guess)) {
  print(guess.code); // 'fr'
}

// Cheap script-only routing, without running the n-gram stage:
detector.dominantScript('こんにちは'); // 'Hira'

Classes

Detected
A language was identified with confidence at or above the detector's minConfidence threshold.
DetectionResult
The result of LanguageDetector.detect.
LanguageDetector
Detects the language of a piece of text.
LanguageDetectorBackend
A pluggable language-scoring strategy.
LanguageGuess
A detected language with its confidence in [0.0, 1.0].
Undetermined
No language met the detector's minConfidence threshold.