All add-ons currently require PHP 7.4 or greater.

On July 4th 2024 PHP 8.2 will be the new minimum requirement for all add-ons. Expect any add-on released after that date to require 8.2 or greater. Some releases may not immediately take advantage of 8.x specific features in PHP, which means you might, be able to continue using new releases in PHP 7.4, however, if you experience an error the first thing you should do is update to PHP 8.2 then create a support ticket if the error persists.

Please read about the changes to BoldMinded add-on licensing.

Ticket: Language change doesn’t work for coming back to default language in homepage

Status Resolved
Add-on / Version Publisher 3.10.1
Severity
EE Version 7.3.5

Juan Carlos Celaya Dibout

Jul 12, 2023

Hi,

Multilingual menu switches back and forth languages for all pages EXCEPT if you change language in homepage and then want to switch back to default language.

Attached is screenshots of the url translation settings, below is relevant template code for menu removing most of the surrounding html.

{exp:publisher:languages}
            {if '{is_active}' == ''}
                <li menuitem itemscope itemtype="http://schema.org/SiteNavigationElement">
                    <a itemprop="url" href="{translated_url}"></a>
                </li>
            {/if}
            {/exp:publisher:languages}

Thanks in advance for your help.

Regards,

#1

BoldMinded (Brian)

Try the {switch_language_url} variable instead of {translated_url}.

#2

Juan Carlos Celaya Dibout

Thanks Brian, we actually come from {switch_language_url} but problem is it outputs an unique URL with parameters, which redirects to final url, and we need it to output the final translated URL without any redirection for SEO reasons.

That’s why we are using {translated_url} which achieves what we want wonderfully for all pages and languages except for coming back to default language in homepage.

#3

BoldMinded (Brian)

Try adding ?lang_id=X to the URL when there are no language segments.

#4

Juan Carlos Celaya Dibout

thanks, do you have any example code for this?

#5

BoldMinded (Brian)

In the languages loop, from your example above, add something like {if segment_1 == “”}{site_url}?lang_id=1{if:else}{translated_url}{/if}

#6

Juan Carlos Celaya Dibout

mmm, that shows all languages with the same id now so they can’t switch to other languages in homepage, well they click but they come back to the same.

Is there some conditional i can use so it only shows that code if there is no segment AND the language id is not 1?

#7

BoldMinded (Brian)

{if segment_1 == "" && language_id != 1}
#8

Juan Carlos Celaya Dibout

Thanks, I used this:

<a itemprop=”url” href=”{if segment_1 == “

#9

BoldMinded (Brian)

So everything is working now as expected?

#10

Juan Carlos Celaya Dibout

sorry i forgot to add the code tags, here we go again:

<a ></a>

and it’s like it isn’t taking into account the new condition, it shows exactly same as without it, in homepage the non-default languages are linking to default language with id1.

#11

Juan Carlos Celaya Dibout

i don’t know why it’s eating the code, trying without the a tag

{if segment_1 == "" && language_id != 1}{site_url}?lang_id=1{if:else}{translated_url}{/if}
#12

BoldMinded (Brian)

Ok, I realize this is a copy of an existing ticket as I was helping a co-worker of yours, and I tested this again locally and everything is working as expected. I don’t know why you’re having issues with it (I don’t know anything about your server configuration or any other routing rules or customizations you have), but I don’t see anything on my side that indicates there is an issue with Publisher. This is the template code I’m using, and I have my URL Translation settings set to exactly what you have.

<ul class="submenu">
    {exp:publisher:languages}
    <li>
        <a href="http://{switch_language_url}">{long_name}</a>
    </li>
    {/exp:publisher:languages}
</ul>

(ignore the https added in front of the switch_language_url variable, that is the code block getting messed up)

The default language, English in my case, does not have a language code added to the home page. The other languages do, and the switching works as expected.

You will need to create a fresh EE installation with only Publisher installed and replicate the issue in that environment.

#13

Juan Carlos Celaya Dibout

Thanks Brian, we actually come from {switch_language_url} but problem is it outputs an unique URL with parameters, which redirects to final url, and we need it to output the final translated URL without any redirection for SEO reasons.

That’s why we are using {translated_url} which achieves what we want wonderfully for all pages and languages except for coming back to default language in homepage.

#14

BoldMinded (Brian)

Try this https://gist.github.com/litzinger/951c8c1466a7c274e8da803c8a2a23e5

#15

BoldMinded (Brian)

You might need to add a segment_1 check in there for your case, but I think that example should get you there.

#16

Juan Carlos Celaya Dibout

Hi, sorry for delay, i tried your code on github but then it wasn’t showing the full url for the other pages, even adding the segment_1 ==”” check, so i tried a mix like this for inside the href

{if segment_1 == "" && id != publisher:default_language_id}{root_url}?lang_id={id}{if:else}{translated_url}{/if}

and well now it outputs urls like https://www.factoriadigital.com/?lang_id=3 for the non-default language, but the default language outputs as https://www.factoriadigital.com (without lang id) and when clicking on this it keeps redirecting to the language you have already selected, can’t come back to default language.

Previously we tried

{if segment_1 == "" && language_id != 1}{site_url}?lang_id=1{if:else}{translated_url}{/if}

and that showed all languages with same id.

So i thought maybe we were complicating things a little, and i used that:

{if segment_1 == ""}{root_url}?lang_id={id}{if:else}{translated_url}{/if}

And that seems to work better, i fine tuned it to that:

{if segment_1 == "" && language_id != 1}{root_url}?lang_id={id}{if:else}{translated_url}{/if}

I understand there is no way that https://www.factoriadigital.com/?lang_id=1 appears as https://www.factoriadigital.com ? i tried a redirect with detour pro but that didn’t seem to do nothing.

#17

BoldMinded (Brian)

Correct, if you’re not using a language code prefix, and not using the switch_language_url variable, then you’re going to need to use the ?lang_id query parameter, there just isn’t another way to force a language change. The only other thing I can think of, and this is totally speculated and not attempted, is to change the site_language_id cookie value when clicking the link with JavaScript before the browser can redirect, and then maybe when the page reloads it will use the cookies value to set the language then.

#18

Juan Carlos Celaya Dibout

Ah yeah, what i mean is that i see that the other language ids redirect to the code prefix after opening them, i.e. clicking on https://www.factoriadigital.com/?lang_id=3 redirects automatically to https://www.factoriadigital.com/pt-pt/, https://www.factoriadigital.com/?lang_id=1 should redirect to root url if the option for not using language prefix for homepage is enabled.

No idea how hard that is or if it is feasible but consider it like feature request or improvement for future releases.

Regards,

Login to reply