Language Switcher Does Not Appear in Joomla

We were working on a bilingual project today and we added the language switcher module to the top right of the website. The language switcher appeared for one language, but did not appear for the other.

For example, when the website was in French, then we were able to see the language switcher on the top right, but if it was in English, then the language switcher just wasn’t there. We thought that it we could just re-write the module from scratch as it’s just an easy module, all we had to do was to detect the current language using the following code:

	$currentLanguage= & JFactory::getLanguage();
	$currentLanguageTag= $currentLanguage->getTag();
	if ($currentLanguageTag== 'fr-FR'){
		[echo link to the French version of the website];
	}
	else{
		[echo link to the English version of the website];
	}

Once we have the language, we would be able to display the right link to the other language (or languages). But there was more to that, as we needed to make sure that the menu items match when switching from one language to another, for example, if we are on this page http://www.ourclientjoomlawebsite.com/en/store, then when switching to French, the link should automatically switch to http://www.ourclientjoomlawebsite.com/fr/magazin. That meant that our little module would not be as easy as we originally thought (and it’ll be like re-inventing the wheel), so we decided to take another look to see why Joomla’s built in language switcher module does not work.

We opened the file modules/mod_languages/helper.php and we checked what were the things that were being done in that module, and we noticed that the module had the following code that prevented the display of a language under certain conditions:

	// Do not display language without frontend UI
	if (!JLanguage::exists($language->lang_code)) {
		unset($languages[$i]);
	}
	// Do not display language without specific home menu
	elseif (!isset($homes[$language->lang_code])) {
		unset($languages[$i]);
	}
	// Do not display language without authorized access level
	elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
		unset($languages[$i]);
	}

We were confident that the issue was because at least one of the conditions above was true, and so we added an echo statement in each condition, and we noticed that the second condition returned true – which meant that there wasn’t a homepage for the other language (in our condition, it was the French language, and that’s why the language switcher did not display a link to switch to French when in English). We already created a main menu item for the French language, but it wasn’t set as a homepage. All we needed to do was to set that menu item to homepage in Joomla’s backend and the problem was solved.

Note that there are two other reasons on why the language switcher module does not appear/partially appears on your website: 1) you don’t have a menu item altogether for one or more languages or 2) you have some wrong permissions set on the homepage menu item for one or more languages (for example, you are only allowing registered visitors to view the homepage of your French version).

If you are trying to build a bilingual/multi-lingual Joomla website and you need help, then you’re in the right place. We are experienced in building multi-lingual websites in Joomla and we are confident that we can help you. Go ahead, contact us; our rates are cheap, our work is fast, and our quality is immaculate!

No comments yet.

Leave a comment