Multilingual site
Created 7 years ago by joeI'm developing a site which has each page available in 3 different languages, what's the best way of rewriting URLs to make sure they go to the right language?
At the moment in my menu I have /products which loads the English page. When I change language (from a dropdown) I need to make the current page reload to the selected language, and have all links off that page going to the selected language (if there is one).
Ah sweet cheers. Does it change the locale whenever you visit /fr/*, or do I need to make a URL to tell it to do it ? I went to /fr/products and it shows the french version as expected, but going to a different page it goes straight back to English, although all of the backend is now in French so I'm guessing something went into the session xD.
The session language doesn't actually change but you will want to make sure and use the URL generator instead of simple strings {{ url('the/page') }}
. It will write in the locale if defined this way like /fr/the/page
.
If you use the query string way - it's session persistent. Which also affects your backend active language (not default though of course).
You can use
?_locale=ISO
in the URI to use the core hook to do it - it will redirect back to the page with the new locale set in session. You can also use a URI prefix for the language like/fr/products
. The URL Generator will accomodate the locale either way automatically.