> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/lang/helpers.md).

# Helpers

The package exposes three global helpers.

## `current_lang()`

```php
function current_lang(): ?string
```

Returns the current language string from 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, $params = null): ?string
```

Returns the translated string for a key.

```php
$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 `$params` is provided

`$params` can be a string or an array.

## `_t()`

```php
function _t(string $key, $params = null): void
```

Echoes 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

* The helpers do not load translations by themselves. They rely on the shared `Lang` instance 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/lang/helpers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
