Hi everyone,
I'm setting up my first multilingual site with wappler in NodeJs.
In the main layout I inserted a condition that checks the existence of the cookie and if it doesn't find it it sets the language value to IT (Italian is the default language).
If I click on the English language I set the cookie to EN and the UI updates in real time but two problems emerge that I don't know how to solve.
The first is that the url remains with reference to Italian (it), the second is that even all the metadata of the page managed through server side action do not change.
So I thought of linking the dictionary using the parameter present in the query string (query.lang) and making a redirect to the same page but referring to the new language.
But now I don't understand how to manage the home that I don't think can have the lang parameter in the url since at the first start the site starts with the url localhost:3000
Can I set an optional parameter for the index in the routing file or even make it so that when I type www.domainname.com it responds with a url of this type (www.domainname.com/home/en)?
If your default language is Italian then check if query.lang=='EN' then load it otherwise load the default
dmx-bind:url="'/data/main/dictionary/'+query.lang=='EN'? query.lang:'IT'+'.json'"
And you can of course check in your layout page.load event the same thing...
If query.lang doesn't exist, set the default
Yes, you can specifiy the available languages as well in brackets: /:lang(it,en)
If nothing set it will redirect to the default with the routing. You still need to think about redirection when the browser language or users prefered language is different than the one set already. Right now I only use one language but I plan to open a modal in this case and save the setting in a cookie variable, then redirect. Pretty much the same logic as cookie consent.