Search by

bytic / locale-detector

gabrielsolomon

Locale detection for Symfony and PSR-7 server requests

Package info

github.com/bytic/locale-detector

pkg:composer/bytic/locale-detector

Statistics

Installs: 7 078

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.12 2026-11-26 21:53 UTC

This package is auto-updated.

Last update: 2026-11-26 21:58:32 UTC


README

Detect a locale from a Symfony HTTP Foundation request or a PSR-7 ServerRequestInterface, including requests from bytic/http.

composer require bytic/locale-detector
use Nip\Locale\Detector\Detector;

$locale = Detector::detect($request); // string or null

By default, the detector checks the lang and language query parameters, then the nip_locale cookie. It uses the parsed PSR-7 query and cookie parameters when given a server request. To also check Accept-Language, specify the desired stage order:

$locale = Detector::detect($request, [], ['query', 'cookie', 'acceptlanguage']);

The optional second argument lists supported locales. A detected locale not in that list causes an InvalidLocale exception; an empty list accepts any locale. The first detected locale wins.