PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Basic

Detect the Active Site Language Tag

Returns the active BCP-47 language tag (such as pt-BR or en-GB) using $app->getLanguage()->getTag().

Updated on 24 November 2026 48 copies 188 views
templates/seu_template/index.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$langTag = Factory::getApplication()->getLanguage()->getTag();

if ($langTag === 'en-GB') {
    // Lógica específica para inglês
} else {
    // Lógica padrão (ex: pt-BR)
}
Uses Factory::getApplication()->getLanguage() recommended in Joomla 5 and 6.
templates/seu_template/index.php
<?php
$lang = JFactory::getLanguage();

if ($lang->getTag() == 'en-GB') {
    // código para en-GB
} else {
    // código para demais idiomas
}
Legacy Joomla 3 snippet via JFactory::getLanguage().

Technical explanation and best practices

Essential in multilingual websites to adapt date formats, regional URLs, currency formatting or conditional templates.

In Joomla 5 and 6, replace deprecated JFactory::getLanguage() with Factory::getApplication()->getLanguage()->getTag().

Direct Engineering

Have a Joomla project or technical challenge in mind?

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