? Pending

User tests: Successful: Unsuccessful:

avatar Giuse69
Giuse69
7 Mar 2020

Remove default language SEF tag (e.g. "en") from URL in mod_languages helper when "Language Filter" plugin configuration is set to do that (Remove URL Language Code = YES).
This is a proposed fix for Issue #26480.

Summary of Changes

When building the list of URLs in the existing languages for the mod_languages, strip the default language prefix from the source code in the switcher with a regexpr in the case the Remove URL Language Code setting in the Language Filter system plugin is set to YES.

Testing Instructions

Create a multilanguage site with English as default language and LANG2, with language switcher module published, SEF enabled and all other stuff to have a multilingual site.
In the Language Filter plugin, set Remove URL Language Code = YES .
Create for example two articles in the two languages and associate one each other.
In front end, go to the article in LANG2 and look at the source link for English in the language switcher module.

Expected result

With this PR, the URL is without the "en" tag in the URL.

Actual result

Without this PR, the URL has the "en" tag in the URL even if the option in the language filter plugins requires it to be removed.

Documentation Changes Required

avatar Giuse69 Giuse69 - open - 7 Mar 2020
avatar Giuse69 Giuse69 - change - 7 Mar 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Mar 2020
Category Modules Front End
avatar brianteeman
brianteeman - comment - 7 Mar 2020

Without this PR, the URL has the "en" tag in the URL even if the option in the language filter plugins requires it to be removed.

Can not confirm.

avatar brianteeman
brianteeman - comment - 7 Mar 2020

To prove my statement go to www.joomla.org/3

If your browser is in english then there is no /en on the url

avatar Giuse69
Giuse69 - comment - 7 Mar 2020

There is: change the language to non English and then look at the language switcher for English: the link is "https://www.joomla.org/3/**en**/"
I am making a fix on the PR to avoid naming conflict

avatar brianteeman
brianteeman - comment - 7 Mar 2020

It is not about what the switcher says it is what the url in the address bar says

avatar Giuse69 Giuse69 - change - 7 Mar 2020
Labels Added: ?
avatar Giuse69
Giuse69 - comment - 7 Mar 2020

Crawlers read the link in the modules, then yes when they will request that links they will get a 301 redirect to another URL without the tag but why not showing the final URL to the crawlers without having google index to track non-indexed URLs since they get redirected? That's the purpose of this PR :)

avatar Giuse69
Giuse69 - comment - 7 Mar 2020

I personally got URLs with "en" showing in google results for my sites

avatar infograf768
infograf768 - comment - 7 Mar 2020

Looks like this does not create an issue. Has to be tested in all situations.

avatar brianteeman
brianteeman - comment - 7 Mar 2020

For clarity you are referring to the link in the source of the switcher and not the URL in the address bar as a result of using the switcher. That's what I didn't understand from the original description

avatar infograf768
infograf768 - comment - 7 Mar 2020

In fact, there is a culprit.
It breaks the home page switch.
The reason is the cookie set when you switch from another language home page to the default site language home page.

I would close this.

avatar Giuse69
Giuse69 - comment - 7 Mar 2020

@brianteeman: yes, I didn't specify esplicitly it, I will update the description.
@infograf768: why it would break the home page? It just get rid of the "en" if there is one. I am using also in the home page: should I have to test some specific situations? I am available

avatar Giuse69 Giuse69 - change - 7 Mar 2020
The description was changed
avatar Giuse69 Giuse69 - edited - 7 Mar 2020
avatar infograf768
infograf768 - comment - 7 Mar 2020

A cookie is set. Therefore, when switching, the cookie is used as there is no indication that the language changes. This is why we never implemented that change in the switcher.
It shows only on the home page because we have there a pure domain url.

Here French (fr) is the default site language. I first make sure I display the English home page then try to switch:

switcher

avatar infograf768
infograf768 - comment - 7 Mar 2020

The only way it would work is to use the setLanguageCookie($languageCode) method from the languagefiter plugin and set the cookie to the default lang.

But, evidently, this can't be done in the module helper.

avatar Giuse69
Giuse69 - comment - 7 Mar 2020

Sorry, I have difficulties in understanding the problem but surely it's my fault. In the case of a site with French as default language, I have a URL=site homepage with switcher flags showing site for French (itself) and site/en/ for English. Same values appear when in the English homepage.
So it's not clear for me the cookie issue, but if you say that we need to set language cookie, we could invoke setLanguageCookie?

`public static function setLanguageCookie($languageCode)
{
$app = JFactory::getApplication();
$plugin = \JPluginHelper::getPlugin('system', 'languagefilter');
$params = new \JRegistry($plugin->params);

// If is set to use language cookie for a year in plugin params, save the user language in a new cookie.
if ((int) $params->get('lang_cookie', 0) === 1)
{
	// Create a cookie with one year lifetime.
	$app->input->cookie->set(
		JApplicationHelper::getHash('language'),
		$languageCode,
		time() + 365 * 86400,
		$app->get('cookie_path', '/'),
		$app->get('cookie_domain', ''),
		$app->isHttpsForced(),
		true
	);
}

// If not, set the user language in the session (that is already saved in a cookie).
else
{
	JFactory::getSession()->set('plg_system_languagefilter.language', $languageCode);
}

}`

avatar Bakual
Bakual - comment - 7 Mar 2020

In the switcher module, the language tag is needed so Joomla knows which language it should switch to. Without the tag, it assumes the currently active language based on the cookie setting.

Also, it is architecturally wrong to change the module behavior based on a plugin parameter. So this PR wouldn't acceptable anyway.

I'm going to close this as it is intended behavior and not a bug.

avatar Bakual Bakual - change - 7 Mar 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-03-07 19:22:56
Closed_By Bakual
avatar Bakual Bakual - close - 7 Mar 2020
avatar Giuse69
Giuse69 - comment - 8 Mar 2020

Hi, of course the boss here is you :) so ok, but just a final comment on this closure:

  • yes, architecturally extensions must be independent each other, but the language filter plugin and the language switcher module work together, infact it is esplicitly stated in bold in the plugin description "this plugin is to be enabled only when the Language Switcher module is published."
  • It's not clear for me the need for Joomla to know which language to switch to: in the module a URL is presented to the browser without the tag and when that URL is invoked by the browser, a valid page is returned where the language is explicitly reported in the header. Probably I am missing the case that Infograf reported.

I got links indexed by Google with the default lang tag instead of actual URL, that's why I was proposing something.
best regards

avatar pulsarinformatique
pulsarinformatique - comment - 24 Feb 2021

Yes, I know this is closed but Google sees both urls: with and without the default language prefix, bad thing

avatar Bakual
Bakual - comment - 24 Feb 2021

Yes, I know this is closed but Google sees both urls: with and without the default language prefix, bad thing

No, it's not a bad thing. It doesn't matter at all.

avatar Slava287
Slava287 - comment - 28 Mar 2022

When the site is large and then it will have a lot of redirects, what then in this case?

Add a Comment

Login with GitHub to post a comment