Download the PHP package avvertix/language-detect-php without Composer

On this page you can find all versions of the php package avvertix/language-detect-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package language-detect-php

Language Detection in PHP

Latest Version on Packagist Tests Total Downloads

Detects the natural language and writing system of a text. 70 languages, 25 scripts, no extensions beyond mbstring, no network calls, no model files to download.

This is a port of whatlang-rs by Sergey Potapov.

Installation

Requires PHP 8.4 and ext-mbstring.

Usage

detect() returns null when the text carries no signal — empty, whitespace, digits and punctuation only, or every candidate language filtered out.

Just the language, or just the script

detectScript() is much cheaper than a full detection: it only counts characters per Unicode block and skips language scoring entirely.

Narrowing the candidates

If you know the text can only be one of a handful of languages, say so. Accuracy on short texts improves considerably.

Confidence

confidence runs from 0.0 to 1.0 and reflects how far ahead the winning language is of the runner-up, scaled by how much text there was to go on — a short text needs a bigger lead to earn the same confidence. isReliable() is true above 0.9.

Detection method

Method What it does When it helps
Combined (default) Blends the two below, weighted by text length Almost always
Trigram Compares three-character frequency profiles Longer texts
Alphabet Scores languages by the characters they use Very short texts; fastest

The combined method leans on the alphabet score for short input and shifts its weight to trigrams as the text grows past roughly a hundred characters.

Supported languages and scripts

How it works

  1. Script detection. Every character is matched against the Unicode ranges of 25 scripts; the script with the most characters wins. Punctuation and digits are ignored.
  2. Script to language. Most scripts imply a single language — Georgian script means Georgian — and detection stops there with full confidence. Five scripts (Latin, Cyrillic, Arabic, Devanagari, Hebrew) are shared, and go on to step 3.
  3. Language scoring. The alphabet pass scores each candidate by the characters it uses. The trigram pass ranks the text's three-character sequences by frequency and compares that ranking against each language's stored profile of its 300 most common trigrams.

Mandarin is special-cased: its script is also used to write Japanese, so the two are told apart by how much Kana is mixed in.

Parity with whatlang-rs

tests/fixtures/reference.json holds 783 samples with the language, script and confidence whatlang-rs produces. Test ReferenceParityTest ensure parity between the PHP implementation and the Rust implementation.

To regenerate the fixture you need cargo and a checkout of whatlang-rs beside this one:

The trigram profiles and alphabet tables under resources/ are likewise generated from the Rust sources rather than transcribed by hand:

Testing

Credits

Derivation

Language Detection PHP is a derivative work of whatlang-rs (Rust, MIT) by Sergey Potapov. The detection algorithm, the trigram profiles and the alphabet tables all originate there.

License

The MIT License (MIT). Please see License File for more information.


All versions of language-detect-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package avvertix/language-detect-php contains the following files

Loading the files please wait ...