Hi all,
So I’m working on a website that will need to be in both English and Portuguese. The client would like it so that before entering the website, there is a page where you can choose the language.
How would I go about doing this?
This was a middle of development request, thankfully adding a second language wasn’t difficult through Kirby panel but am looking for ways to add that splash page without having to restructure my current homepage blueprint.
You could use $kirby->detectedLanguage() (more info) in the home-controller to try to detect the language of the visitor.
You can enhance the experience by adding a modal in the client-side (via JS) where you politely ask the user if the current language is ok, and if not present him/her with options. Please store his preference in a cookie afterwards and let this setting have priority above all of the above (don’t redirect on detected language / don’t show JS modal anymore).
The reason for the portal is the client doesn’t want one language to appear to be the default given they have a lot of English and Portuguese speaking visitors to the site.
I haven’t thought of how to best approach the domain. I just set up the languages through the panel last night and saw that Kirby creates separate subdirectories for different languages. That’s fine with me tbh but if you believe feel setting up different subdomains would be easier, I’d be happy to hear how so.
That’s why I was asking about the domain setup. Big sites like IKEA, for example, use a .com domain for the language portal, and country/language specific domains for the different language versions, but such a solution would probably be overkill? I think it also depends on which domain has been the go-to domain in the past, and there are probably SEO considerations to take into account (but I can’t give advice on this). Kirby already has an option for automatic language detection based on browser language, which you can set in the config. It would still allow you to switch languages. I’d probably go with something like this rather than a portal, but if the client absolutely wants that?
Automatic language detection sounds good but I think the client would still like to give the visitors the ability to choose as well as the ability to alternate.
How about a full page overlay that works on every page instead? (the sort of thing people do to make u turn off an adblocker). You can remember the choice via cookie so that it doesnt show again.
That way, it wont matter which page someone hits first. You cant gaurentee they will always enter the site on the home page. Put the language switcher inside the popup.
Then you have to either go with a Javascript option or use another URL, e.g. make the lang switcher page the home page, but then you would have the home part in the URLs for the actual home page.
I normally set and read cookies with Vanilla JS like this, set the cookie in the button click to choose the language, then just wrap your fade in to happen if the cookie value does not equal what you set it too.
I think in this case you also have to read the cookie on the server side, to decide if language redirection based on browser language should happen or not depending on the user preference stored in the cookie.
server gets the request for the page
server checks cookie value
if no cookie is set, language redirection happens based on browser language
on the client side, the user is presented with the overlay when no cookie is set
when the user dismisses the overlay, the cookie is set on the JS side, storing the value of the language in the cookie
when the user clicks on the link to the other language, they are redirected to the other language, the cookie value is set to this new language
Is your javascript in the head of the page, or the footer? Personally, I would do it on javascript click event in the javascript file, rather then directly on the html elememt.