How to detect the current language of a Joomla! website?

 See getLanguage in JFactory:

$lang = JFactory::getLanguage();
echo 'Current language is: ' . $lang->getName();

Once you have the language, you can also retrieve the locale/language code (e.g. en-US). Joomla! languages can have multiple locales, so you'll get an array.

$lang = JFactory::getLanguage();
foreach($lang->getLocale() as $locale) {
echo 'This language supports the locale: ' . $locale;

If for some reason, you are only interested in the first locale, you can simply grab the first element. You will probably need an array, like this:

$lang = JFactory::getLanguage();
$locales = $lang->getLocale();
echo 'This language\'s first locale is: ' . $locales[0];

If you just want to get the selected language tag (e.g. pt-PT) you can use getTag()

$lang = JFactory::getLanguage();
echo 'Current language is: ' . $lang->getTag();


Display the Year in your Joomla template

Sometimes you need to display the current date or ideally the current year, typically in copyright notices or anywhere else required by your template. The following simple php function will allow you to easily achieve this. Find the area where you want to display the year, this is probably somewhere in the index.php of your template, or possibly in the footer.php. Then addd the following code:

This takes the current date and displays only the year. Obviously, if you don't need the copyright notice you will need to change the text to what you require, but this is basically what you will need. There are more options which you can use with the PHP date function, you can find more information on what you can do with the date function @ There are many variations which you can use for the displaying information related to dates.

© 2024, Joomla King

Contact Info