franc-cli: Language Detection CLI

8.0.0 · active · verified Wed Apr 22

franc-cli is a command-line interface (CLI) tool for detecting the natural language of textual input. It acts as a convenient shell wrapper around the core `franc` library, which supports identifying over 180 languages, including various scripts and dialects. The current stable version for `franc-cli` is 8.0.0, which corresponds to breaking changes introduced in `franc` library versions 6.x.x. The project generally follows the `franc` library's release cadence, with updates often driven by new Unicode versions or improvements in language detection models. Its key differentiator is providing quick, direct command-line access to language detection without requiring programmatic integration, making it suitable for shell scripting, data processing pipelines, and rapid prototyping. It is an ESM-only package, requiring Node.js version 12 or higher for execution.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically execute the `franc-cli` command-line tool from a Node.js script using `child_process` and capture its output to detect the language of a given text string.

import { spawn } from 'child_process';

const textToAnalyze = "Alle menslike wesens word vry en gelyk in waardigheid en regte gebore.";

const child = spawn('franc-cli', [textToAnalyze]);

let output = '';
child.stdout.on('data', (data) => {
  output += data.toString();
});

child.stderr.on('data', (data) => {
  console.error(`stderr: ${data}`);
});

child.on('close', (code) => {
  if (code === 0) {
    console.log(`Detected language: ${output.trim()}`);
  } else {
    console.error(`franc-cli exited with code ${code}`);
  }
});

view raw JSON →