51Degrees Pipeline for PHP

fiftyone\pipeline\translation\Languages Class Reference

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()

fiftyone\pipeline\translation\Languages::localeFromFilename ( string $name)
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()

fiftyone\pipeline\translation\Languages::parseAcceptLanguage ( ?string $acceptLanguage)
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()

fiftyone\pipeline\translation\Languages::tryResolveLocale ( ?string $acceptLanguage,
array $availableLocales,
?string & $matchedLocale,
string $baseLanguage = 'en' )
static

Resolve an Accept-Language value to an available locale.

Resolution rules, applied to each candidate in quality order:

  1. An exact case-insensitive match against an available locale wins.
  2. 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.
  3. 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
-outstring|null $matchedLocale