I needed to create a website in two languages English and Arabic. So, I created two versions of the site using folders but I was looking for a way to have a language switcher to just change the slug from “en” to “ar” in the url. I viewed some of the posts about localization and couldn’t find what I was looking for.
After some googling I managed to do it with the following:
As the pages of my landing language (which is “Chinese / 中文” in my case) are located at the root folder. When switching from “Chinese” homepage to “English”, the script will output /en/ but not /en/home.
I tried to play around with window.location.host, but not able to figure it out…
I know it’s simpler if I place the pages of landing language to a folder, but it is not an option for client.
Another problem… my site will have 3 languages finally. I have no idea how to add the third language, say “Japanese”, and making 2 or a total of 3 language options links or list inside a div for language switching.