Join the Webstudio community

Updated 3 months ago

Language switcher again 🌐

At a glance

The community member is seeking help to implement a language switcher for a website built with Hygraph, where the default English pages are on the root and the Arabic translation pages are in the "/ar/" folder. The content is appearing correctly, but the community member needs to implement a switcher in the navigation that directs users to the "/ar/" version without taking them back to the homepage.

The community member has tried multiple methods, including some suggested by other users, but none of them have worked as expected. One method worked only on the first page load, as it read the URL, but it didn't work after that. The community member eventually found a solution that worked, but they were unsure what they were doing wrong in the previous versions.

There is no explicitly marked answer in the comments, but the community member seems to have found a solution that worked for them.

Posting this request again.
How can we implement a language switcher please.
Content is from Hygraph with languages enabled

In WS, English default pages are on root and duplicated translation pages are in folder AR

URLs are set up fine "website.com/ar/news" (for arabic)
"website.com/news" (For default english)
Content is appearing correctly too.

Need to implement a switcher in navigation that directs to /ar/ version without taking user back to homepage

It's for a large-ish site we're rebuilding and wanting client to move from WordPress to WebStudio . It is unfortunately time-based so need to finalize this soon so we don't have to continue new site on Wp again

Thanks a lot
O
m
5 comments
So did you try writing a bit of js for this?
I tried multiple methods via chatgpt tbh
Also one user suggested another JS too but none worked unfortunately
Something like this worked only on first page load as it reads the URL but after that it doesn't
Attachment
image.png
what doesn't work, can you show an example and the exact problem?
I tried this again now with fresh slot and tested in published version again and this above script solved the switcher . I must be doing somethign wrong in previous version
sorry and thanks again
Add a reply
Sign up and join the conversation on Discord