A multilingual site with "Remove URL language" options set to YES in system - language filter plugin to remove default language tag from URL.
SEF enabled in global configuration.
Create an article in default language (es. "en"), an article in non default language (es. "it") and associate them.
Create a menu item "Article list" to show articles.
Select NON default language in front-end (it).
In the article list, after the article title, there is the language flag with a link that points to associated article in the default language (en).
The URL of the language flag link does NOT contain the default language tag in the URL (no "/en") since the system plugin requires that.
The URL of the language flag link DOES contain the default language tag ("/en/...")
Joomla 3.9.12
Linux
Labels |
Added:
?
|
After click, the joomla router redirects 301 to correct url without the default language flag. it seems to me that already the displayed link should take into account the system language setting.
Same behavior in single article page (just found now that)
Thanks
As far as I understand the router it is by design. The router needs the language code in the link so it knows where to redirect to, then the language code is removed at the end if it is the default language. So I don’t think this can be easily changed.
This is working as intended. If you search hard enough you will see several other discussions on this which go into more detailed explanation
That was what I tried to say, that it works as intended. Thanks for confirming my understanding.
Yes, but it is inconsistent: the language flag links in the language switcher module work better and default language tag is stripped before displaying the link.
The same flag link in the page body does not and relies on later router redirect.
I don't think so: that PR was about mod_language: with current Joomla 3.9.12 I see that problem solved: the lang mod switcher presents ULR without def lang code, can you please confirm?
Current Issue is not for mod_language but for the body where a flag link appears close to article title, in single article view or in article list view.
Also href in the <head>
is already set correctly without the default language, so in this issue I am proposing to aling the construction of the flag link in the page as it is already done in mod_language and in href. Hope that now is more clear.
Deleted my former post.
There is no change for the switcher. The sef prefix does not display in the switcher ONLY when the page is already in the default language AND it is the Home Page.
As @ReLater said, we failed solving this (and not sure at all it is even possible).
Not what I see in my sites.
An example: English and Italian languages, default English with associated articles.
I go to an article in Italian and this is what I see:
page URL = https://site/**it**/foto/notizie/2040-confronto
flag link in lang switcher = https://site/photo/news/2041-comparison
href in head = href="https://site/photo/news/2041-comparison"
flag link in the article ("also available in") = https://site/**en**/photo/news/2041-comparison
I added ** around lang tags
I absolutely can't reproduce the link you get in the switcher when hovering the flag (en-GB is default). Same in J4.
Page url:
http://localhost:8888/installmulti/trunkgitnew/fr/catblogfrench/article-fr-fr
Link for the English flag in the switcher:
http://localhost:8888/installmulti/trunkgitnew/en/catblogenglish/article-en-gb
Alternate in head:
<link href="http://localhost:8888/installmulti/trunkgitnew/catblogenglish/article-en-gb" rel="alternate" hreflang="en-GB" />
LInk in the info-block of the article:
http://localhost:8888/installmulti/trunkgitnew/en/catblogenglish/article-en-gb
I can here modify the flag link in the article info-block to get rid of the sef prefix.
I modified the file /layouts/joomla/content/info_block/associations.php
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
$default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
// Get default lang prefix param from languagefilter plugin
$plugin = JPluginHelper::getPlugin('system', 'languagefilter');
$params = new JRegistry($plugin->params);
$remove_default_prefix = $params->get('remove_default_prefix', 0);
?>
<?php if (!empty($displayData['item']->associations)) : ?>
<?php $associations = $displayData['item']->associations; ?>
<dd class="association">
<?php echo JText::_('JASSOCIATIONS'); ?>
<?php foreach ($associations as $association) : ?>
<?php $link = JRoute::_($association['item']); ?>
<?php if ($remove_default_prefix && $association['language']->lang_code === $default_lang) : ?>
<?php $link = preg_replace('|/' . $association['language']->sef . '/|', '/', $link, 1); ?>
<?php endif; ?>
<?php if ($displayData['item']->params->get('flags', 1) && $association['language']->image) : ?>
<?php $flag = JHtml::_('image', 'mod_languages/' . $association['language']->image . '.gif', $association['language']->title_native, array('title' => $association['language']->title_native), true); ?>
<a href="<?php echo $link; ?>"><?php echo $flag; ?></a>
<?php else : ?>
<?php $class = 'label label-association label-' . $association['language']->sef; ?>
<a class="<?php echo $class; ?>" href="<?php echo $link; ?>"><?php echo strtoupper($association['language']->sef); ?></a>
<?php endif; ?>
<?php endforeach; ?>
</dd>
<?php endif; ?>
Here is the modified file that you can test:
Not sure of the eventual consequences though.
Hi, instead of modifying associations.php, why not simply modify helper.php at the end with code
if ($remove_default_prefix && isset($languages[$default_lang]->link)) { $languages[$default_lang]->link = preg_replace('|/' . $languages[$default_lang]->sef . '/|', '/', $languages[$default_lang]->link, 1); self::setLanguageCookie($default_lang); }
?
I'm closing this issue as it is intended behavior and not a bug.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-03-07 19:24:22 |
Closed_By | ⇒ | Bakual |
and what is the actual link displayed in the urlbar AFTER you have clicked the language flag