filterLanguages.php
Table of Contents
Functions
- filterLanguages() : array<string, string|null>|null
- Filter an array or object of translations according to the given or available languages.
Functions
filterLanguages()
Filter an array or object of translations according to the given or available languages.
filterLanguages(mixed $fields[, array<string|int, string>|null $languages = null ][, callable|null $sanitize = null ]) : array<string, string|null>|null
This helper transforms an input array/object from the client to prepare a multilingual (i18n) property. It keeps only string or null values, allows optional transformation or sanitization via a callback.
Note: this helper is permissive on input shape — invalid inputs (string, scalar, etc.) silently return null rather than throwing. Callers that need to reject invalid shapes (e.g. to return a 422) must validate the raw input upstream before calling this helper.
Parameters
- $fields : mixed
-
Input translations (array<string,string|null> or object). Any other shape (string, scalar, …) is treated as invalid and ignored — the function returns null. Type validation must be done upstream by callers.
- $languages : array<string|int, string>|null = null
-
Optional array of languages to filter the i18n definitions. If null, no filtering is applied.
- $sanitize : callable|null = null
-
Optional callback to transform or sanitize each value. Signature:
fn(string|null $value, string $lang): string|null
Tags
Return values
array<string, string|null>|null —Filtered translations matching the languages, or null if input is empty.