@iaminiamin/lang-text-detect
v0.1.1
Published
Simple offline-first text language detector with optional LibreTranslate fallback.
Maintainers
Readme
lang-text-detect
Simple offline-first language detection for short text.
Website: https://livetalktranslate.com/
- Default: local detection (no paid API, no network).
- Optional fallback: LibreTranslate
/detect. - Works in Node.js 18+.
Install
npm install @iaminiamin/lang-text-detectUsage (JS)
import { detectLanguage } from "@iaminiamin/lang-text-detect";
const result = await detectLanguage("hola gracias por tu ayuda");
console.log(result);
// { language: 'es', confidence: 0.95, source: 'local', ... }Usage with fallback (LibreTranslate)
import { detectLanguage } from "@iaminiamin/lang-text-detect";
const result = await detectLanguage("blorpt zibble flargh", {
remoteUrl: "https://your-libretranslate-host",
minConfidence: 0.8
});CLI
lang-text-detect "bonjour merci beaucoup"
lang-text-detect "hola gracias" --json
echo "blorpt zibble flargh" | lang-text-detect --remote-url https://your-libretranslate-host --jsonAPI
detectLanguage(text, options?)
Returns best result. Uses local detection first, then optional remote fallback.
Options:
remoteUrl?: stringremoteApiKey?: stringminConfidence?: number(default0.65)timeoutMs?: number(default2500)fetchImpl?: typeof fetch(for testing/custom runtime)
detectLanguageLocal(text)
Local-only detection (fast, no network).
detectWithLibreTranslate(text, options)
Remote-only detection using LibreTranslate /detect.
Output shape
{
language: "es", // ISO-639-1 or "und"
confidence: 0.95, // 0..1
source: "local", // "local" | "libretranslate"
candidates: [
{ language: "es", confidence: 0.95 }
]
}Notes
- This package is intentionally lightweight.
- Local detection is heuristic-based; for production-grade accuracy, use remote fallback.
