supportpal/accept-language-parser

An alternative to ext-intl's locale_accept_from_http function.

v0.2.1 2022-05-27 10:45 UTC

This package is auto-updated.

Last update: 2024-03-28 13:39:47 UTC


README

68747470733a2f2f7777772e737570706f727470616c2e636f6d2f6173736574732f696d672f6c6f676f5f626c75655f736d616c6c2e706e67
A PHP port of npm:accept-language-parser and an equivalent to the ext-intl locale_accept_from_http function.

Build Status Total Downloads Latest Stable Version License

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.