Don't show flags if there is no association

General questions regarding the use of languages in Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Sevbanchik
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 20, 2019 12:07 pm

Don't show flags if there is no association

Post by Sevbanchik » Thu Jun 20, 2019 12:22 pm

Hello!
First of all – sorry for my English.
Secondly.

I don't like, how does the language switcher work. Now it shows links to category on second language, if there is no association to it.
E.g. there are three languages on site and only two pages – in English and in German. They are associated. And there is no page for Spanish. Links from switcher on English page look like this:

site.com/en/category/page1.html
site.com/de/category/page1.html
site.com/es/category.html

If there is no association to the page, I don't want to see that site.com/es/category.html

There are 3000 pages in English, 3000 in German and only 50 in Spanish. It's not good for SEO. And for usability too.

I think it is hidden somewhere there /modules/mod_languages/helper.php
But i can't find out, what should I change there...

Thanks in advance for your help!

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28202
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Don't show flags if there is no association

Post by imanickam » Thu Jun 27, 2019 5:44 am

If you are referring to the flag images in the Language Switcher module then be informed that the flags would show for the languages that have default menu item defined for them.

In the URLs provided, whether the URLs are being typed manually or are there menu items for them?

Whether the categories and articles are assigned to appropriate language?

Whether the Language Switcher module has been published. If the answer is "Yes" whether the module has been published to appropriate menu items.

In these circumstances, it would be easier to visualize things if the URL to the website is given.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Don't show flags if there is no association

Post by infograf768 » Fri Jun 28, 2019 4:51 am

Mig, I think the original poster wants to NOT display the flag (or lang name) in the switcher when an item has no association in the language concerned which means unsetting the language in that case in the helper.
I am not sure it is possible. If I have time, will look into it.
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28202
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Don't show flags if there is no association

Post by imanickam » Fri Jun 28, 2019 5:50 am

Oops... Yes, I reread the title and I apologize for misunderstanding the requirement.

Right now, if there is no association, the flag link would take the user to the language's default page.

So, my current understanding is that the user wants to change the behavior by not showing the flag at all if there is no association.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

Sevbanchik
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 20, 2019 12:07 pm

Re: Don't show flags if there is no association

Post by Sevbanchik » Sat Jun 29, 2019 3:06 pm

Hello! What i've done? A added next code and it works, but only with com_content. And only if articles and/or categories have associations. If articles are not associated one to other and Menus are associated – it doesn't work properly.

Code: Select all

elseif ( ((!isset($cassociations[$language->lang_code]) && !$menu->getItem($associations[$language->lang_code]))) )
			{
				unset($languages[$i]);
			}

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Don't show flags if there is no association

Post by infograf768 » Sun Jun 30, 2019 7:41 am

That will never work because we always need to have

Code: Select all

				else
					{
						if ($language->active)
						{
							$language->link = JUri::getInstance()->toString(array('path', 'query'));
						}
						else
						{
							$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
							$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
						}
					}
If we don't, for all other cases the Switcher will be totally empty.
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

Sevbanchik
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 20, 2019 12:07 pm

Re: Don't show flags if there is no association

Post by Sevbanchik » Sun Jun 30, 2019 11:46 am

I have that lower. I'll show you the whole part that I have now.

Code: Select all

// Filter allowed languages
foreach ($languages as $i => &$language)
	{
	// Do not display language without frontend UI
	if (!array_key_exists($language->lang_code, $sitelangs))
	{
		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]);
	}
	/* This is added by me */
	elseif ( ((!isset($cassociations[$language->lang_code]) && !$menu->getItem($associations[$language->lang_code]))) )
	{
		unset($languages[$i]);
	}
	elseif ( ((!isset($cassociations[$language->lang_code]) && (isset($homes[$language->lang_code])))) ) 
	{
		unset($languages[$i]);
	}
	/* End of added part */
	else
	{
		$language->active = ($language->lang_code === $lang->getTag());

		// Fetch language rtl
		// If loaded language get from current JLanguage metadata
		if ($language->active)
		{
			$language->rtl = $lang->isRtl();
		}
		// If not loaded language fetch metadata directly for performance
		else
		{
			$languageMetadata = JLanguageHelper::getMetadata($language->lang_code);
			$language->rtl    = $languageMetadata['rtl'];
		}

		if ($multilang)
		{
			if (isset($cassociations[$language->lang_code]))
			{
				$language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
			}
			elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code]))
			{
				$itemid = $associations[$language->lang_code];
				$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
			}
			elseif ($active && $active->language == '*')
			{
				$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $active->id);
			}
			else
			{
				if ($language->active)
				{
					$language->link = JUri::getInstance()->toString(array('path', 'query'));
				}
				else
				{
					$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
					$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
				}
			}
		}
		else
		{
			$language->link = JRoute::_('&Itemid=' . $homes['*']->id);
		}
	}
}
I don't know php and Joomla! :) Adding something intuitively :)


Locked

Return to “Language - Joomla! 3.x”