Introduction to the Franc Project
Franc is a remarkable software library designed to determine the language of a given text. With this tool, users can identify the language out of hundreds of possibilities, making it an invaluable resource in today's multilingual world.
Unique Features of Franc
-
Broad Language Support: Franc stands out due to its extensive language support. It can handle more languages than any other similar library, offering support for 82, 186, or even 419 languages. This range is based on the Universal Declaration of Human Rights, the most translated document without copyright in the world.
-
Versatile CLI: Franc offers a command-line interface (CLI), allowing users to interact with it directly through a terminal.
-
Different Package Options:
- Franc-min: Supports 82 languages, catered to languages spoken by 8 million or more people.
- Franc: Supports 187 languages, covering those spoken by 1 million or more people.
- Franc-all: A comprehensive package supporting 414 languages, allowing for the broadest language detection.
Requirements and Installation
Franc is an ESM-only package, which means it's designed to work smoothly with modern JavaScript practices. To use Franc:
-
In Node.js (version 14.14+ or 16.0+), install it via npm:
npm install franc
-
For Deno, import it using esm.sh:
import {franc, francAll} from 'https://esm.sh/franc@6'
-
In web browsers, Franc can be included as a module:
<script type="module"> import {franc, francAll} from 'https://esm.sh/franc@6?bundle' </script>
How to Use Franc
Franc provides two main functions:
- franc(): Detects the most probable language for a given string.
- francAll(): Returns a list of potential languages with confidence scores.
For example:
import {franc, francAll} from 'franc'
franc('Alle menslike wesens word vry') // Outputs: 'afr'
franc('এটি একটি ভাষা একক IBM স্ক্রিপ্ট') // Outputs: 'ben'
// List all language possibilities with scores
console.log(francAll('Considerando ser essencial que os direitos humanos'))
Command Line Interface (CLI)
Franc's CLI is easy to use and highly customizable:
# Detect language of text
$ franc "Text here"
# Specify minimum character length
$ franc --min-length 5 "Short text"
# Restrict detection to certain languages
$ franc --only en,fr "Bonjour le monde"
# Ignore specific languages
$ franc --ignore fr,es "Hello world"
Compatibility and Ports
Franc is compatible with all maintained versions of Node.js and works well with Deno and modern browsers. It has been ported to several other programming languages such as Elixir, Erlang, Go, R, Rust, Dart, and Python, which speaks to its versatility and widespread utility.
Language Codes
Franc returns language codes based on the ISO 639-3 standard, which are three-letter codes. While ISO 639-3 covers a vast range of languages, it is important to note that not all codes map to the shorter ISO 639-1 codes.
Contributing and Security
The Franc project welcomes contributions from the community. It maintains a focus on security, ensuring that the software is safe to use.
Franc is licensed under the MIT license, indicating a permissive and flexible usage policy.