Repository navigation
Configuration
Rumen Damyanov edited this page Dec 4, 2026
·
1 revision
use Rumenx\PhpLangid\DetectorConfig;
use Rumenx\PhpLangid\IndexMode;
use Rumenx\PhpLangid\LanguageDetector;
use Rumenx\PhpLangid\ShareScale;
$detector = new LanguageDetector(
(new DetectorConfig())
->withMinShare(6000)
->withMinMargin(2000)
->withNoiseFloor(500)
->withMaxLanguages(4)
->withIndexMode(IndexMode::Order)
->withShareScale(ShareScale::BasisPoints)
->withOnlyLanguages(['en', 'bg', 'fr', 'sv'])
);The decisive check uses basis points, before percent rounding. The top language must reach minShare, and its lead over the second language must reach minMargin. Languages under noiseFloor are removed and the remaining shares are scaled to 100% (10000 basis points) before that check.
| Method | Default | Range |
|---|---|---|
withMinShare |
5500 | 0–10000 |
withMinMargin |
1500 | 0–10000 |
withNoiseFloor |
200 | 0–10000 |
withMaxLanguages |
0 | 0 keeps every remaining language |
withChunkChars |
280 | at least 20, and at least minChunkLetters
|
withMinChunkLetters |
50 | 1 through chunkChars
|
withMinLetters |
40 | at least 1 |
withMaxBytes |
5242880 | at least 1 |
withMaxFiles |
5000 | at least 1 |
IndexMode |
indexed() |
|---|---|
Language |
['en' => 52, 'fr' => 48] |
Share |
[[52, 'en'], [48, 'fr']] |
Order |
[['language' => 'en', 'name' => 'English', 'share' => 52]] |
ShareScale::Percent sums to 100. ShareScale::BasisPoints sums to 10000. withMaxLanguages truncates the list after scaling.
withOnlyLanguages accepts lowercase or uppercase codes. An unknown code fails with unknown_language when detection runs.
Invalid numbers throw LangidException with reason invalid_config.
See Files and directories for the file limits.
php-langid is maintained by Rumen Damyanov.