Feature: #108627 - Allow adding inline language domains to JavaScript
See forge#108627
Description
The new method
Page allows loading
all labels from a language domain and making them available in JavaScript
via the
TYPO3. object.
The domain name follows the format extension. (e.g. core.,
'core.modules.media').
The language file is resolved automatically by the LanguageService, resolving
to files like EXT:
and EXT:.
See translation domain syntax for more details.
Labels are automatically prefixed with the domain name and accessible as
TYPO3., e.g.
TYPO3..
Example
use TYPO3\CMS\Core\Page\PageRenderer;
final class MyController
{
public function __construct(
private readonly PageRenderer $pageRenderer,
) {}
public function myAction(): void
{
// Load all labels from the 'myextension.frontend' domain
$this->pageRenderer->addInlineLanguageDomain('myextension.frontend');
}
}
The labels are then available in JavaScript:
// Access a label from the domain
const label = TYPO3.lang['myextension.frontend:button.submit'];
Impact
Previously, it was possible to load entire language files using
add (which is still available), but labels
were added without any prefix.
This could lead to naming conflicts when multiple extensions used the same
label keys, potentially overriding each other's translations.
With the new domain-based approach, all labels are automatically prefixed
with the domain name (e.g. myextension.). This provides
a unified, namespaced access pattern that eliminates the risk of collisions
between labels from different extensions or language files.