?
avatar Giuse69
Giuse69
4 Oct 2019

Steps to reproduce the issue

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).

Expected result

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.

Actual result

The URL of the language flag link DOES contain the default language tag ("/en/...")

System information (as much as possible)

Joomla 3.9.12
Linux

avatar Giuse69 Giuse69 - open - 4 Oct 2019
avatar joomla-cms-bot joomla-cms-bot - change - 4 Oct 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Oct 2019
avatar brianteeman
brianteeman - comment - 4 Oct 2019

and what is the actual link displayed in the urlbar AFTER you have clicked the language flag

avatar Giuse69
Giuse69 - comment - 5 Oct 2019

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

avatar richard67
richard67 - comment - 5 Oct 2019

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.

avatar brianteeman
brianteeman - comment - 5 Oct 2019

This is working as intended. If you search hard enough you will see several other discussions on this which go into more detailed explanation

avatar richard67
richard67 - comment - 5 Oct 2019

That was what I tried to say, that it works as intended. Thanks for confirming my understanding.

avatar Giuse69
Giuse69 - comment - 5 Oct 2019

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.

avatar ReLater
ReLater - comment - 5 Oct 2019

Duplicate: #23144

And all related PRs failed.

avatar Giuse69
Giuse69 - comment - 5 Oct 2019

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.

avatar Giuse69
Giuse69 - comment - 6 Oct 2019

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.

avatar infograf768
infograf768 - comment - 8 Oct 2019

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).

avatar Giuse69
Giuse69 - comment - 9 Oct 2019

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

avatar infograf768
infograf768 - comment - 10 Oct 2019

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); ?>
			&nbsp;<a href="<?php echo $link; ?>"><?php echo $flag; ?></a>&nbsp;
		<?php else : ?>
			<?php $class = 'label label-association label-' . $association['language']->sef; ?>
			&nbsp;<a class="<?php echo $class; ?>" href="<?php echo $link; ?>"><?php echo strtoupper($association['language']->sef); ?></a>&nbsp;
		<?php endif; ?>
	<?php endforeach; ?>
</dd>
<?php endif; ?>

Here is the modified file that you can test:

associations.php.zip

Not sure of the eventual consequences though.

avatar infograf768
infograf768 - comment - 11 Oct 2019

@ReLater
What do you think about this patch?

avatar Giuse69
Giuse69 - comment - 4 Mar 2020

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); }
?

avatar Bakual
Bakual - comment - 7 Mar 2020

I'm closing this issue as it is intended behavior and not a bug.

avatar Bakual Bakual - close - 7 Mar 2020
avatar Bakual Bakual - change - 7 Mar 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-03-07 19:24:22
Closed_By Bakual

Add a Comment

Login with GitHub to post a comment