This article is machine translated.
Multilingual websites are also implemented in Contao by using different websites in the site structure. In contrast to the multi-domain mode, the domain name is not used to differentiate between websites but the language.
In general, there are two ways to display multilingual websites:
In Contao, only the first variant is supported (except for some third party extensions that differ from this concept for managing your own content).
In order for the language to be added to the URL (e.g.
www.example.com/de/), you must add the following lines in the
app/config/. If the file does not exist yet, you have to create it.
From version 4.8 of Contao the file is located in the folder
contao: prepend_locale: true
activate the changes, the application cache must be refreshed via the Contao Manager (“System maintenance” > “Refresh product cache”) or alternatively via the command line.
vendor/bin/contao-console cache:clear --env=prod --no-warmup
The combination of domain name, language and language fallback creates four possibilities that Contao has to check with every frontend call:
The check is carried out from the most specific case, in which both the domain and the browser language match, to the most general case, in which neither the domain nor the browser language match and therefore the welcome page is loaded. Let us illustrate this with a concrete example scenario.
Let’s assume you have two domains, one business and one private:
The business side is bilingual, so you need a total of three starting points:
DNS settings for the different starting points
|Page||Domain name||Language||Language fallback|
Depending on the called domain and the language set in the browser, visitors will be redirected as follows:
Forwarding of visitors to the different starting points
The first three cases all lead to the company page, even if the domain
firma.deis not explicitly stored in theDNS settings. This is not necessary at all, because the company page is in this case the starting page for unknown domains.
The first two cases could be clearly assigned to a starting point based on the browser language, only in the third case the language fallback page had to be loaded. The third case is therefore the most general case, which catches all requests that cannot be uniquely assigned.
The fourth case clearly belongs to the private website because of the domain, no matter what language the visitor speaks, and thanks to the language fallback, surfers all over the world have access to the website. And here you can see the importance of a language fallback: without it, the private website would only be available for German speaking visitors! all others would only see a “No pages found”.