PrepareLang uses trait:short
Table of Contents
Properties
- $languages : array<string|int, string>
- The enumeration of all valid languages used by the controller.
Methods
- filterLanguages() : array<string, mixed>|null
- Filter an array of translations according to the available languages.
- initializeLanguages() : static
- Initialize the internal `$languages` property from an array or a PSR-11 container.
- translate() : mixed
- Retrieve the translation for a specific language, or fallback to the default language.
- prepareLang() : string|null
Properties
$languages
The enumeration of all valid languages used by the controller.
public
array<string|int, string>
$languages
= []
Methods
filterLanguages()
Filter an array of translations according to the available languages.
public
filterLanguages(array<string, mixed>|null $field[, bool $html = false ]) : array<string, mixed>|null
This helper transforms an input array from the client to prepare a multilingual (i18n) property.
Example input: [ 'fr' => 'bonjour', 'en' => 'hello' ]
Parameters
- $field : array<string, mixed>|null
-
The input array of translations.
- $html : bool = false
-
If true, strip inline styles from HTML content.
Return values
array<string, mixed>|null —Filtered translations matching available languages, or null if input is empty.
initializeLanguages()
Initialize the internal `$languages` property from an array or a PSR-11 container.
public
initializeLanguages([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Parameters
- $init : array<string|int, mixed> = []
-
Optional initialization array, expected key: ControllerParam::LANGUAGES
- $container : ContainerInterface|null = null
-
Optional PSR-11 container for fallback configuration
Tags
Return values
statictranslate()
Retrieve the translation for a specific language, or fallback to the default language.
public
translate(array<string, mixed> $texts[, string|null $lang = null ]) : mixed
Parameters
- $texts : array<string, mixed>
-
Array of translations keyed by language codes.
- $lang : string|null = null
-
The desired language code. If null, returns the full array.
Return values
mixed —The translated text for the requested language, fallback, or full array if no match.
prepareLang()
protected
prepareLang(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : string|null
Parameters
- $request : ServerRequestInterface|null
- $args : array<string|int, mixed> = []
- $params : array<string|int, mixed>|null = null