Lang Helpers
The package exposes three global helpers. All three use the shared Lang instance of the default adapter (lang.default), resolved through LangFactory::get().
current_lang()
php
function current_lang(): ?stringReturns the current language code of the shared Lang instance.
Use it when you need the language code for routing, view logic, or response metadata.
t()
php
function t(string $key, array|string $params = null): ?stringReturns the translated string for a key.
php
$title = t('custom.test');
$message = t('custom.info', ['new']);Behavior:
- the
fileadapter loads the translation files on the first call - returns the key unchanged when no translation exists
- replaces
{%1},{%2}, ... placeholders when$paramsis provided;$paramscan be a string or an array
_t()
php
function _t(string $key, array|string $params = null): voidEchoes the result of t() directly.
php
_t('custom.test');This is mainly convenient in views when you want immediate output instead of assigning a variable first.
Helper caveats
- With the
fileadapter, the firstt()throwsTranslation files not found.when neithershared/resources/lang/<lang>/nor the current module has translation files. - The helpers share one
Langinstance per adapter for the container's lifetime, sosetLang()on that instance changes the language of every later helper call.
