JavaScript Joomla! 6 Joomla! 5 Joomla! 4 Template Basic

Translate Frontend JavaScript Strings with Text::script() and Joomla.Text._()

Exposes .ini language constants from PHP with Text::script() and resolves localized labels cleanly using Joomla.Text._().

Updated on 24 November 2026 48 copies 162 views
media/com_example/js/app.js
// No PHP: Text::script('COM_EXAMPLE_COPIED');
//         Text::script('COM_EXAMPLE_RESULTS_FMT');
const copiedLabel = Joomla.Text._('COM_EXAMPLE_COPIED', 'Copiado!');

// Substituição de placeholders %d / %s
const rawSummary = Joomla.Text._('COM_EXAMPLE_RESULTS_FMT', 'Exibindo %d de %d');
const summary    = rawSummary.replace('%d', String(12)).replace('%d', String(100));
Automatically resolves strings in the active site language.

Technical explanation and best practices

Eliminate hardcoded UI strings in JavaScript by calling Text::script('COM_EXAMPLE_SAVED') in your PHP view and reading the translated text via Joomla.Text._().

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.