Don't show flags if there is no association
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.
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.
-
- Joomla! Fledgling
- Posts: 3
- Joined: Thu Jun 20, 2019 12:07 pm
Don't show flags if there is no association
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!
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!
- imanickam
- 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
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.
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
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged
- infograf768
- 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
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.
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
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
- imanickam
- 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
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.
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
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged
-
- Joomla! Fledgling
- Posts: 3
- Joined: Thu Jun 20, 2019 12:07 pm
Re: Don't show flags if there is no association
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]);
}
- infograf768
- 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
That will never work because we always need to have
If we don't, for all other cases the Switcher will be totally empty.
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);
}
}
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Fledgling
- Posts: 3
- Joined: Thu Jun 20, 2019 12:07 pm
Re: Don't show flags if there is no association
I have that lower. I'll show you the whole part that I have now.
I don't know php and Joomla! Adding something intuitively
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);
}
}
}