Wrong language switcher address

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

Moderators: infograf768, 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.
Post Reply
keianrad
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Sep 08, 2017 5:02 am

Wrong language switcher address

Post by keianrad » Wed Oct 17, 2018 9:34 am

I updated my Joomla from 3.8.7 to 3.8.13 then it made an issue for home menu links.

My websites is multilingual site (Farsi/English). both home menus created by feature article.

When I click on switcher language it goes to the address listed below:

Farsi:
.../index.php?option=com_content&amp;view=featured&amp;Itemid=144&amp;lang=fa

English:
.../index.php?option=com_content&amp;view=featured&amp;Itemid=101&amp;lang=en

when I click on the home menu it goes to the address listed below:
Farsi home menu:
.../index.php?option=com_content&view=featured&Itemid=101&lang=fa

English home menu:
.../index.php?option=com_content&view=featured&Itemid=101&lang=en

I don't know what is "amp;" in the switcher address?!

Search Engine Friendly URLs option also is disabled

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Wed Oct 17, 2018 9:43 am

&amp; is the websafe escaped ampersand (&) So the URI actually all mean the same.

It should not be escaped in a URI but most modern browsers are capable of translating.

it may be the character encoding is somewhere off. Is all (site, db etc..) set to UTF-8?

keianrad
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Sep 08, 2017 5:02 am

Re: Wrong language switcher address

Post by keianrad » Wed Oct 17, 2018 10:18 am

Thank you for your reply. I checked the DB, some of tables are "utf8_general_ci" and some "utf8mb4_general_ci"

keianrad
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Sep 08, 2017 5:02 am

Re: Wrong language switcher address

Post by keianrad » Wed Oct 17, 2018 8:22 pm

Any suggestion? it didn't solve yet.

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Thu Oct 18, 2018 5:44 am

I wonder... what is your URI? Do you have any custom created extension or template? Your language switcher has no customizations or template override?

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 18, 2018 8:20 am

Looks like the switcher does its job OK as the Itemid is different for farsi and english.

It looks though that your menus homes have an issue with the Itemid.

Are you sure you have a menu module for each language mainmenu containing its specific home, module tagged to that specific language?
Are you sure that the menu module for the main menu with a home menu item tagged to ALL languages is NOT published or does not exist?
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 18, 2018 8:22 am

Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Thu Oct 18, 2018 10:14 am

The URI are pretty much the same, but the "&" get escaped to "&amp;" by the language switcher. Not something a browser worries much about but still...

I just checked on one of my sites. When I unset SEF urls in the config, same happens with me.
Now I went to look some deeper and made a template override on the module.

When I replace all "htmlspecialchars(JUri::current(), ENT_COMPAT, 'UTF-8')" for just "JUri::current()" it shows the URI okay in the sites language switcher.
override.zip
Drop it in your template to see if this works.

@infograf768 I added this as issue on Github: https://github.com/joomla/joomla-cms/issues/22693
You do not have the required permissions to view the files attached to this post.

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 18, 2018 1:58 pm

That is not the user's issue imho.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Fri Oct 19, 2018 8:17 am

Imho it is exactly what reporter describes, I observed the same in my multlingual sites (set up according to the instrcutions), and the code did change in the past.

https://github.com/joomla/joomla-cms/co ... 382df893e1

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

Re: Wrong language switcher address

Post by infograf768 » Fri Oct 19, 2018 10:44 am

I was speaking of the other issue, i.e.
Farsi home menu:
.../index.php?option=com_content&view=featured&Itemid=101&lang=fa

English home menu:
.../index.php?option=com_content&view=featured&Itemid=101&lang=en
which have the same Itemid which is blatantly wrong.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Fri Oct 19, 2018 11:17 am

Maybe you need read by any typo caused by copy paste.. check my site for which I turned off the SEF and renamed htaccess... hover the flags to see.... current mod_languages. &amp; instead of &

https://bizgo.nl

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

Re: Wrong language switcher address

Post by infograf768 » Fri Oct 19, 2018 1:15 pm

I am now asking jsst why htmlspecialchars was added in
https://github.com/joomla/joomla-cms/co ... 382df893e1
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

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

Re: Wrong language switcher address

Post by infograf768 » Fri Oct 19, 2018 1:19 pm

OK. This is the reason.
https://developer.joomla.org/security-c ... her-module

I will now close the github issue
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Fri Oct 19, 2018 3:23 pm

I took a peek in the code of other modules.. see how they are made up.. they show fine...

Not handy to do this in two places... ;) better continue here https://github.com/joomla/joomla-cms/issues/22693

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 25, 2018 6:52 am

Please test https://github.com/joomla/joomla-cms/pull/22558
It solves this as well as another issue with current link.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Thu Oct 25, 2018 9:20 am

SEF disabled, htaccess not renamed.

if I use current code:

Code: Select all

htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8')
I get &amp; instead of & - not ok.

with last changes as in https://github.com/joomla/joomla-cms/co ... f28edfce7f

Code: Select all

htmlspecialchars_decode(htmlspecialchars($base, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES)
I get just the base.. just domain.com, can no longer switch languages. there is just domain.tld under each flag, association have gone. Not ok.

The next two do work.

If I use code:

Code: Select all

JFilterOutput::ampReplace(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8', FALSE))
I get & - ok - even though this follows similar conventions as in mod_menu, this code replacement is turned down.

If I use code:

Code: Select all

htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8', FALSE)
I get & - ok

It seems to me, the "double encode" flag is doing the trick actually. From https://www.w3schools.com/php/func_stri ... lchars.asp:
double_encode Optional. A boolean value that specifies whether to encode existing html entities or not.

TRUE - Default. Will convert everything
FALSE - Will not encode existing html entities


I noticed this error not always happens. I do have a site which is practically similar. This one shows URLs ok with current code.
Only difference is that one (the one with errors originates (originally built) somewhere around j! 3.2 whereas the other started round 3.6 or 7 i guess... now both at 3.8.13 but one has more rounds of updates.

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 25, 2018 9:42 am

Code: Select all

htmlspecialchars_decode(htmlspecialchars($base, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES)
is ONLY used when clicking on the flag (or lang name) of the same language which is in use (Language Active displayed). Link is

Code: Select all

$base
.

Otherwise, the code used is

Code: Select all

htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES)
The reason we use

Code: Select all

htmlspecialchars
in the first place is to forbid doublequotes (") but use

Code: Select all

&quot;
I don't want to explain here in details why we should never have doublequotes in the possible url as this was the reason of the patch.
I get just the base.. just domain.com, can no longer switch languages. there is just domain.tld under each flag, association have gone. Not ok.
I do not confirm this issue, neither did the other tester.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 25, 2018 9:53 am

Examples of links from switcher with associations after my PR:

Code: Select all

index.php?option=com_content&view=article&id=2:article-fr-fr&catid=9&lang=fr&Itemid=123

index.php?option=com_content&view=article&id=1:article-en-gb&catid=8&lang=en&Itemid=122
or

Code: Select all

index.php?option=com_content&view=category&layout=blog&id=9&Itemid=123&lang=fr

index.php?option=com_content&view=category&id=8&lang=en&layout=blog&Itemid=122
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

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

Re: Wrong language switcher address

Post by infograf768 » Thu Oct 25, 2018 9:58 am

BTW, my tests are in 3.9.0/staging, not yet released.
To test fully, install staging or last beta. Patch with the PR.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Thu Oct 25, 2018 11:34 am

mmmhh, but we are talking of odd behaviour in current 3.8.13 so I assume behaviour can be different between 3.8.13 and 3.9.0?

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Thu Oct 25, 2018 1:12 pm

I don't want to explain here in details why we should never have doublequotes in the possible url as this was the reason of the patch.
But isn't that what ENT_QUOTES flag is for?
So that should do ok.

I fail to see why the convention used in mod_menu (modules/mod_menu/tmpl/default_url.php in both 3.8.13 and 3.9.0) line 66...

Code: Select all

JFilterOutput::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false))
...is pefectly fine there but not in mod_languages.
In mod_articles_latest, it is even less... just...

Code: Select all

$item->link
Three ways of creating a link, all doing their bit.. But now for me it becomes confusing.

emililadjet
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Oct 06, 2018 2:39 pm

Re: Wrong language switcher address

Post by emililadjet » Thu Oct 25, 2018 5:53 pm

If you use the FaLang component, it will be easier for you to manage the different language of the site

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

Re: Wrong language switcher address

Post by infograf768 » Fri Oct 26, 2018 5:35 am

@waarnemer

Both JFilterOutput::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false))
and
htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES)
work fine.

The PR is now merged in staging.
You can test 3.9.0-rc2 by downloading and installing it. It is a RC, i.e. not production ready!

https://github.com/joomla/joomla-cms/re ... ackage.zip
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Fri Oct 26, 2018 8:33 am

I tested, but here

Code: Select all

htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES)

does NOT work.

It will just show the base... no way to select another language as base redirects to default language home.

If this

Code: Select all

JFilterOutput::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false))
..works as expected.

If that works in both (your and mine) setup, and it is also the convention used in for example Mod_menu.. then I would choose this one as the proposed solution. Being the code that works for all.

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

Re: Wrong language switcher address

Post by infograf768 » Sat Oct 27, 2018 5:01 am

> It will just show the base... no way to select another language as base redirects to default language home.

Once and for all, this is wrong.

Code: Select all

<?php foreach ($list as $language) : ?>
			<?php if (!$language->active) : ?>
				<li>
				<a href="<?php echo htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
					<?php if ($language->image) : ?>
						<?php echo JHtml::_('image', 'mod_languages/' . $language->image . '.gif', '', null, true); ?>
					<?php endif; ?>
				<?php echo $language->title_native; ?>
				</a>
				</li>
			<?php elseif ($params->get('show_active', 1)) : ?>
				<?php $base = JUri::getInstance(); ?>
				<li class="lang-active">
				<a href="<?php echo htmlspecialchars_decode(htmlspecialchars($base, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
					<?php if ($language->image) : ?>
						<?php echo JHtml::_('image', 'mod_languages/' . $language->image . '.gif', '', null, true); ?>
					<?php endif; ?>
				<?php echo $language->title_native; ?>
				</a>
				</li>
			<?php endif; ?>
		<?php endforeach; ?>
When clicking on another language than the one in use, it does not use base at all but "$language->link"
When param is to show Active Language, the link is "$base" for that icon/name of lang and will show base, i.e. reload the same page .

If you do not get that, it means your site is badly configured.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

waarnemer
Joomla! Ace
Joomla! Ace
Posts: 1982
Joined: Sun May 04, 2008 12:37 pm

Re: Wrong language switcher address

Post by waarnemer » Tue Oct 30, 2018 7:30 pm

My sites are configured properly.. I have been doing multlingual sites since joomfish and have been using my own solution working the language settings in Joomla! even before your module was made part of the core, remember?
viewtopic.php?t=633828

Since then I am using the instructions you created. But for step 6. I do not copy a template per language if there is no reason to (such as country/language/cultural design differences that can be configured in parameters)

But on this topic: My point is why introduce a new convention of code for creating URI, when there are already correctly working ones as in mod_menu?
I would expect that all URI in the code should be the same all over J!. This convention should also be advertised so extension developers use the same. This way avoiding the security risk that triggered all this in the first place.


Post Reply

Return to “Language - Joomla! 3.x”