Skip to content

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

Notifications You must be signed in to change notification settings

Koenster/php-language-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP localization / language detection script

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.

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages