The package exposes three global helpers.
function current_lang(): ?stringReturns the current language string from the shared Lang instance.
Use it when you need the language code for routing, view logic, or response metadata.
function t(string $key, $params = null): ?stringReturns the translated string for a key.
$title = t('custom.test');
$message = t('custom.info', ['new']);Behavior:
- reads from the shared language service used by the current app container
- returns the key unchanged when no translation exists
- applies placeholder substitution when
$paramsis provided
$params can be a string or an array.
function _t(string $key, $params = null): voidEchoes the result of t() directly.
_t('custom.test');This is mainly convenient in views when you want immediate output instead of assigning a variable first.
- The helpers do not load translations by themselves. They rely on the shared
Langinstance already being loaded, which normally happens during web app bootstrap when multilingual support is enabled. - If translations were not loaded yet, lookups fall back to the key string.
- Helpers use the same shared language instance across the request/container lifecycle, so manual runtime changes to that instance affect later helper calls.