langdetect-ruby
Language detection for Ruby using n-gram profiles. Supports 10+ languages with script-based fast paths for CJK, Arabic, Thai, and Devanagari.
Installation
gem "langdetect-ruby"Usage
require "lingua_ruby"
# Single detection
result = LinguaRuby.detect("This is an English sentence")
result.language # => :en
result.confidence # => 0.92
# Batch detection
results = LinguaRuby.detect_batch([
"Hello world",
"Halo dunia",
"こんにちは世界"
])
# Restrict to specific languages
detector = LinguaRuby::Detector.new(languages: [:en, :id, :ms])
result = detector.detect("Selamat pagi")Features
- N-gram profile comparison with normalized confidence (0.0-1.0)
- CJK/Arabic/Thai/Devanagari script fast-path detection
- Short text mode (< 20 chars) with higher n-gram orders
- Batch detection with single profile load
- Indonesian/Malay/Sundanese differentiation
- Input validation and error handling
License
MIT