DefaultLangTrait
Carries the **default language** — the locale a multilingual expression falls back to when the requested one is absent, or when no language is requested at all.
⚠ Not to be confused with the language requested by the current call
(?lang=, see PrepareLang). The two
travel side by side and mean opposite things: the requested language is an
instruction, and it wins over everything; defaultLang is a default, and
a default never overrides an explicit declaration. That is why they cannot
share a name.
It is also distinct from LanguagesTrait, its sibling: languages is
the set a request is allowed to ask for, defaultLang is the one answered
when nothing was asked.
The trait is used at two levels, which is what makes it a trait rather than a property: a model declares the fallback its own multilingual fields use, and a controller reads the site-wide one from the configuration and pushes it into the model call. When both answer, the model wins — a site default must not silently override what a model states about itself, or the model would change behaviour depending on which host loads it.
Tags
Table of Contents
Constants
- DEFAULT_LANG : string = 'defaultLang'
- The 'defaultLang' parameter.
Properties
- $defaultLang : string|null
- The default (fallback) language code, or null when none is declared.
Methods
- initializeDefaultLang() : static
- Initialize the default language, from the `$init` definition or, failing that, from the container entry of the same name.
Constants
DEFAULT_LANG
The 'defaultLang' parameter.
public
string
DEFAULT_LANG
= 'defaultLang'
Properties
$defaultLang
The default (fallback) language code, or null when none is declared.
public
string|null
$defaultLang
= null
Methods
initializeDefaultLang()
Initialize the default language, from the `$init` definition or, failing that, from the container entry of the same name.
public
initializeDefaultLang([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
The tag is lowercased so a single spelling reaches whatever consumes it, and validated on the spot: a language tag names a key of a translations map, so it is interpolated verbatim rather than passed as a parameter, and a declaration nobody can fix from a request must fail loudly rather than quietly answer on nothing.
Parameters
- $init : array<string|int, mixed> = []
-
Optional definition carrying a
defaultLangentry. - $container : ContainerInterface|null = null
-
Optional PSR-11 container for a site-wide fallback.