Detailed Description
Helpers for parsing an HTTP Accept-Language value and resolving it to one of the locales for which a translation map is available.
Static Public Member Functions | |
| static | parseAcceptLanguage (?string $acceptLanguage) |
| Parse an Accept-Language style value into an ordered list of locale candidates, highest quality first. | |
| static | tryResolveLocale (?string $acceptLanguage, array $availableLocales, ?string &$matchedLocale, string $baseLanguage='en') |
| Resolve an Accept-Language value to an available locale. | |
| static | localeFromFilename (string $name) |
| Extract the locale from a translation filename. | |
Data Fields | |
| const | LOCALE_REGEX = '/^[a-z]{2}_[A-Z]{2}$/' |
Member Function Documentation
◆ localeFromFilename()
|
static |
Extract the locale from a translation filename.
The locale is the second-to-last dot separated segment and must match LOCALE_REGEX, so "countries.fr_FR.yml" resolves to "fr_FR".
◆ parseAcceptLanguage()
|
static |
Parse an Accept-Language style value into an ordered list of locale candidates, highest quality first.
Dashes are replaced with underscores so "fr-FR" becomes "fr_FR".
- Returns
- array<string>
◆ tryResolveLocale()
|
static |
Resolve an Accept-Language value to an available locale.
Resolution rules, applied to each candidate in quality order:
- An exact case-insensitive match against an available locale wins.
- Otherwise, if the candidate's language is the base language (en), stop and return false - the source values are already English, so do not fall through to a lower-priority language.
- Otherwise, if the candidate is a two-letter language code, fall back to the first available locale that starts with it.
- Parameters
-
array<string> $availableLocales -out string|null $matchedLocale
