Skip to content

Quick Start

Rumen Damyanov edited this page Dec 4, 2026 · 1 revision

Quick start

use Rumenx\PhpLangid\LanguageDetector;

$detector = new LanguageDetector();
$result = $detector->detect($text);

if ($result->isDecisive()) {
    echo $result->language()->code();
    echo $result->language()->name();
    echo $result->shareOf('en');
} else {
    print_r($result->indexed());
}

outcome() returns the language code when the call is decisive. It returns the indexed distribution when the lead is inside the margin.

primary() is the largest share in either case. languages() lists every language kept after the noise floor.

Default percent output for a near-even English and French text:

['en' => 52, 'fr' => 48]

See Configuration for the other index shapes, Mixed languages for why 52 and 48 stays a distribution, and Examples for directories, HTML, and stored basis points.

Clone this wiki locally