franc

repository·main·Indexed 26 days ago

https://github.com/wooorm/franc

A language detection library using trigram-based analysis that supports up to 414 languages identified by ISO 639-3 codes. Available as an ESM module for Node.js (14.14+ or 16.0+), Deno, and browsers, as well as a CLI tool. The monorepo includes several packages: franc (187 languages), franc-min (82 languages), franc-all (414 languages), and franc-cli.

Tokens
3K
Snippets
4
Records
19
Agent score
87%

What's inside franc

  1. Install franc

    main

    Depending on your environment, install the appropriate package. Note that the standard franc package is ESM only and supports 187 languages.

    • Node.js (14.14+, 16.0+): Use npm.
    • Deno: Use esm.sh.
    • Browsers: Use esm.sh with the ?bundle query parameter.

    Available packages:

    • franc: 187 languages (1M+ speakers).
    • franc-min: 82 languages (8M+ speakers).
    • franc-all: 414 languages (all possible).
    • franc-cli: Command line interface.
    npm install franc
  2. Use the franc-cli to detect languages

    main

    The franc-cli allows you to detect the language of a string via the command line. You can provide the string as a positional argument or pipe text from stdin (expects UTF-8).

    Basic Usage:

    # Detect language from a string argument
    $ franc "Alle menslike wesens word vry"
    
    # Detect language from stdin
    $ echo "এটি একটি ভাষা একক IBM স্ক্রিপ্ট" | franc
  3. Use the franc API

    main

    The franc package exports franc and francAll. Both functions return ISO 639-3 (three-letter) language codes. If a language cannot be determined, they return 'und'.

    • franc(value, [options]): Returns the single most probable language code as a string.
    • francAll(value, [options]): Returns an array of language-distance tuples Array<[string, number]> sorted by probability.
  4. Supported languages in franc

    main

    The franc package supports a wide range of languages identified by ISO 639-3 codes. The following table lists the languages available in this build, their corresponding codes, and approximate speaker counts.

    CodeNameSpeakers
    cmnMandarin Chinese885M
    spaSpanish332M
    engEnglish322M
    rusRussian288M
    arbStandard Arabic280M
    benBengali196M
    hinHindi182M
    porPortuguese182M
    indIndonesian140M
    jpnJapanese125M
    fraFrench124M
    deuGerman121M
    javJavanese (Javanese/Latin)76M
    korKorean75M
    telTelugu73M
    vieVietnamese67M
    marMarathi65M
    itaItalian63M
    tamTamil62M
    turTurkish59M
    urdUrdu54M
    gujGujarati44M
    polPolish44M
    ukrUkrainian41M
    kanKannada38M
    maiMaithili35M
    malMalayalam34M
    pesIranian Persian33M
    myaBurmese31M
    swhSwahili (individual language)30M
    sunSundanese27M
    ronRomanian26M
    panPanjabi26M
    bhoBhojpuri25M
    amhAmharic23M
    hauHausa22M
    fuvNigerian Fulfulde22M
    bosBosnian (Cyrillic/Latin)21M
    hrvCroatian21M
    nldDutch21M
    srpSerbian (Cyrillic/Latin)21M
    thaThai21M
    ckbCentral Kurdish20M
    yorYoruba20M
    uznNorthern Uzbek (Cyrillic/Latin)18M
    zlmMalay (Arabic/Latin)18M
    iboIgbo17M
    npiNepali (individual language)16M
    cebCebuano15M
    skrSaraiki15M
    tglTagalog15M
    hunHungarian15M
    azjNorth Azerbaijani (Cyrillic/Latin)14M
    sinSinhala13M
    koiKomi-Permyak13M
    ellModern Greek (1453-)12M
    cesCzech12M
    magMagahi11M
    runRundi11M
    belBelarusian10M
    pltPlateau Malagasy10M
    qugChimborazo Highland Quichua10M
    madMadurese10M
    nyaNyanja10M
    zybYongbei Zhuang10M
    pbuNorthern Pashto10M
    kinKinyarwanda9M
    zulZulu9M
    bulBulgarian9M
    sweSwedish9M
    linLingala8M
    somSomali8M
    hmsSouthern Qiandong Miao8M
    hnjHmong Njua8M
    iloIloko8M
    kazKazakh8M
    uigUighur (Arabic/Latin)7M
    hatHaitian7M
    khmKhmer7M
    prsDari7M
    hilHiligaynon7M
    snaShona7M
    tatTatar7M
    xhoXhosa7M
    hyeArmenian7M
    minMinangkabau7M
    afrAfrikaans6M
    luaLuba-Lulua6M
    satSantali6M
    bodTibetan6M
    tirTigrinya6M
    finFinnish6M
    slkSlovak6M
    tukTurkmen (Cyrillic/Latin)5M
    danDanish5M
    nobNorwegian Bokmål5M
    sukSukuma5M
    alsTosk Albanian5M
    sagSango5M
    nnoNorwegian Nynorsk5M
    hebHebrew5M
    mosMossi5M
    tgkTajik4M
    catCatalan4M
    sotSouthern Sotho4M
    katGeorgian4M
    bclCentral Bikol4M
    glgGalician4M
    laoLao4M
    litLithuanian4M
    umbUmbundu4M
    tsnTswana4M
    vecVenetian4M
    nsoPedi4M
    banBalinese4M
    bugBuginese4M
    kncCentral Kanuri4M
    kngKoongo3M
    ibbIbibio3M
    lugGanda3M
    aceAchinese3M
    bamBambara3M
    tzmCentral Atlas Tamazight3M
    yddEastern Yiddish3M
    kmbKimbundu3M
    lunLunda3M
    shnShan3M
    warWaray (Philippines)3M
    dyuDyula3M
    wolWolof3M
    kirKirghiz3M
    ndsLow German3M
    fufPular3M
    mkdMacedonian3M
    vmwMakhuwa3M
    zghStandard Moroccan Tamazight2M
    eweEwe2M
    khkHalh Mongolian2M
    slvSlovenian2M
    ayrCentral Aymara2M
    bemBemba (Zambia)2M
    emkEastern Maninkakan2M
    bciBaoulé2M
    bumBulu (Cameroon)2M
    epoEsperanto2M
    pamPampanga2M
    tivTiv2M
    tpiTok Pisin2M
    venVenda2M
    sswSwati2M
    nynNyankole2M
    kbdKabardian2M
    iiiSichuan Yi2M
    yaoYao2M
    lvsStandard Latvian2M
    quzCusco Quechua2M
    srcLogudorese Sardinian2M
    rupMacedo-Romanian2M
    scoScots2M
    tsoTsonga2M
    menMende (Sierra Leone)1M
    fonFon1M
    nhnCentral Nahuatl1M
    dipNortheastern Dinka1M
    kdeMakonde1M
    kbpKabiyè1M
    temTimne1M
    toiTonga (Zambia)1M
    ekkStandard Estonian1M
    snkSoninke1M
    cjkChokwe1M
    adaAdangme1M
    aiiAssyrian Neo-Aramaic1M
    quyAyacucho Quechua1M
    rmnBalkan Romani1M
    binBini1M
    gaaGa1M
    ndoNdonga1M
  5. Language data in franc-all

    main
    The franc-all package includes a comprehensive dataset of languages. The data is represented by ISO 639-3 codes, language names, and approximate speaker counts (or data weight). This allows for more exhaustive language detection compared to the standard franc package.
  6. View supported languages in franc-all

    main

    The franc-all package supports a wide range of languages identified by ISO 639-3 codes. Below is a sample of the supported languages and their approximate speaker counts:

    CodeNameSpeakers
    cmnMandarin Chinese885M
    spaSpanish332M
    engEnglish322M
    rusRussian288M
    arbStandard Arabic280M
    benBengali196M
    hinHindi182M
    porPortuguese182M
    indIndonesian140M
    jpnJapanese125M
    fraFrench124M
    deuGerman121M
    korKorean75M
    vieVietnamese67M
    itaItalian63M
    turTurkish59M
    polPolish44M
    ukrUkrainian41M
    thaThai21M
    hunHungarian15M
    sweSwedish9M
    finFinnish6M
    danDanish5M
    hebHebrew5M
    catCatalan4M
    litLithuanian4M
    lavLao4M
    norNorwegian5M

    (Note: This is a partial list. The full dataset includes many more languages and variations, such as different scripts for Bosnian, Serbian, and Uzbek.)

  7. Configure franc options

    main

    Both franc and francAll accept an optional Options object to refine detection:

    • only: An array of language codes to allow (e.g., ['por', 'spa']).
    • ignore: An array of language codes to exclude.
    • minLength: The minimum string length required for detection (defaults to 10).
  8. Understand language code formats

    main
    Franc returns ISO 639-3 (three-letter) language codes. It does not return ISO 639-1 or ISO 639-2 codes. If you need to map these to ISO 639-1, you may need an external mapping index.