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: 38 018
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 0
Type:project
Requires
- php: >=5.5.9
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2025-03-29 21:58:59 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.