pub fn detect_language(text: &str) -> LanguageExpand description
Heuristically detect the language of an SDS document from its extracted text.
Detection order:
0. Fewer than 30 non-whitespace characters → Language::Japanese (default, not enough text)
- Hiragana or katakana present →
Language::Japanese - No CJK ideographs AND text is substantially Latin (≥ 30 % of meaningful chars are
ASCII printable a-z/A-Z/0-9) →
Language::EnglishThis avoids misclassifying Japanese PDFs whose pdftotext output contains only garbage ASCII (e.g. garbled CID/Shift-JIS font metrics) as English. - Fewer than 20 CJK characters →
Language::Japanese(not enough CJK to distinguish) - Traditional-Chinese-only characters outnumber simplified-only →
Language::ChineseTraditional - Otherwise →
Language::ChineseSimplified
Works on as little as ~200 characters of text. No LLM or network call required.