supportpal / accept-language-parser
An alternative to ext-intl's locale_accept_from_http function.
Installs: 28 294
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-10-28 14:47:21 UTC
README
A PHP port of npm:accept-language-parser and an equivalent to the ext-intl locale_accept_from_http function.
Install
composer require supportpal/accept-language-parser
Usage
Parse
Parses an ACCEPT_LANGUAGE header and returns all parsed locales.
$parser = new \SupportPal\AcceptLanguageParser\Parser($_SERVER['http_accept_language']); foreach ($parser->parse() as $component) { echo $component->code(); }
Pick
Parses an ACCEPT_LANGUAGE header and returns only locales which match those requested.
$parser = new \SupportPal\AcceptLanguageParser\Parser('en-GB;q=0.8'); foreach ($parser->pick(array('en')) as $component) { echo $component->code(); }
License
This package is licensed under the MIT License.