Download the PHP package arosemena/localechooser without Composer
On this page you can find all versions of the php package arosemena/localechooser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arosemena/localechooser
More information about arosemena/localechooser
Files in arosemena/localechooser
Package localechooser
Short Description Locale chooser based on common browser headers
License MIT
Homepage https://github.com/arosemena/localechooser
Informations about the package localechooser
Locale Chooser for PHP
This is a simple class to detect the locale that the user preffers.
Installation
The easiest way to install this is through composer, inside your composer.json require block add
"arosemena/localechooser": "1.0.1"
and then do composer update
, otherwise you could grab the class itself and autoload it with the method of your choosing.
Usage
You will need an instance of the LocaleChooser class, the constructor takes 3 parameters, first an array of the available language, ['en', 'es', 'fr']
for example, the second parameter is a string of the default language in case nothing can be matched, the third parameter is the name of the cookie that contains the language that overrides all the normal priority.
After the class has been instanciated do $chooser->obtain()
to get the appropiate locale.
Examples
How does it work?
The class will read the $_SERVER['HTTP_ACCEPT_LANGUAGE']
variable which is a header sent by most modern browsers and it will be parsed and evaluated against the available languages to determine the most appropiate one.