Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
1234567891011121314151617181920212223// English detection for the first scored cohort.//// The readability formulas, syllable heuristic, whitespace tokenizer and// Zipf list are English-specific. Detecting the language before scoring keeps// the other languages out of a percentile comparison they did not enter// fairly. This is a filter, not a scorer; it stays outside the dependency-free// scoring core.
import { franc } from 'franc'
const MIN_LENGTH = 40const SAMPLE = 4_000export const ENGLISH = 'eng'
/** ISO 639-3 code, or undefined when the sample is too short or ambiguous. */export function detectLanguage(text) { if (typeof text !== 'string') return undefined const sample = text.trim().slice(0, SAMPLE) if (sample.length < MIN_LENGTH) return undefined const code = franc(sample, { minLength: MIN_LENGTH }) return code === 'und' ? undefined : code}