koenster/php-language-detection

Detects the preferred language from the browser and compares this with the available languages/locales to return the best language/locale to redirect.

Installs: 42 133

Dependents: 1

Suggesters: 0

Security: 0

Stars: 4

Watchers: 3

Forks: 1

Open Issues: 0

Type:project

pkg:composer/koenster/php-language-detection

v1.0.4 2016-11-08 14:20 UTC

This package is not auto-updated.

Last update: 2025-09-28 01:27:57 UTC


README

Detects the preferred language from the browser and compares this with the available languages/locales to return the best language/locale to redirect.

How to install

composer require koenster/php-language-detection

How to use


use koenster\PHPLanguageDetection\BrowserLocalization;

$browser = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$default = 'nl-NL';
$available = ['nl-NL', 'nl-BE', 'en-GB', 'fr-FR'];


$browser = new BrowserLocalization();

$browser->setAvailable($available)
    ->setDefault($default)
    ->setPreferences($browser);

// Will return or a default or when available, the available locale.
echo $browser->detect();

##License

This Language Detection script is open-sourced software licensed under the MIT license.