Publisher does not support the Fluid field type. Please do not contact asking when support will be available.
If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.
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, 2023Hi,
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,
BoldMinded (Brian)
Jul 12, 2023
Try the {switch_language_url} variable instead of {translated_url}.
Juan Carlos Celaya Dibout
Jul 12, 2023
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.
BoldMinded (Brian)
Jul 12, 2023
Try adding ?lang_id=X to the URL when there are no language segments.
Juan Carlos Celaya Dibout
Jul 12, 2023
thanks, do you have any example code for this?
BoldMinded (Brian)
Jul 12, 2023
In the languages loop, from your example above, add something like {if segment_1 == “”}{site_url}?lang_id=1{if:else}{translated_url}{/if}
Juan Carlos Celaya Dibout
Jul 12, 2023
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?
BoldMinded (Brian)
Jul 13, 2023
Juan Carlos Celaya Dibout
Jul 13, 2023
Thanks, I used this:
<a itemprop=“url” href=”{if segment_1 == “
BoldMinded (Brian)
Jul 13, 2023
So everything is working now as expected?
Juan Carlos Celaya Dibout
Jul 13, 2023
sorry i forgot to add the code tags, here we go again:
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.
Juan Carlos Celaya Dibout
Jul 13, 2023
i don’t know why it’s eating the code, trying without the a tag
BoldMinded (Brian)
Jul 13, 2023
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.
(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.
Juan Carlos Celaya Dibout
Jul 13, 2023
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.
BoldMinded (Brian)
Jul 14, 2023
Try this https://gist.github.com/litzinger/951c8c1466a7c274e8da803c8a2a23e5
BoldMinded (Brian)
Jul 14, 2023
You might need to add a segment_1 check in there for your case, but I think that example should get you there.
Juan Carlos Celaya Dibout
Aug 01, 2023
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
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
and that showed all languages with same id.
So i thought maybe we were complicating things a little, and i used that:
And that seems to work better, i fine tuned it to that:
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.
BoldMinded (Brian)
Aug 01, 2023
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.
Juan Carlos Celaya Dibout
Aug 01, 2023
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,