If your website serves multilingual audiences you can display the popup in different languages on the same domain. In this article, we’ll show you how to do it.
Before you start
Here are some important things to keep in mind before you start:
There are two ways to set up languages for your consent popup. You can:
Use a plugin for WordPress websites.
Set up multi-language consent popups in settings and create a script that detects URL language codes and adjusts data culture.
You can set only one
data-culture
attribute, a language code, in the popup script for a single domain. Thedata-culture
attribute controls the language in which the popup will appear on the page. For example, setting thedata-culture = "EN"
will display the popup in English. Set thedata-culture
attribute to a different language code to change the language. For more details, see this article.
Note: You can use a plugin such as the WPML to have multiple languages on one domain for WordPress websites. You can find instructions on the plugin's official page.
Set up multi-language consent popups
To set up multi-language consent popups, follow these steps:
1. Log in to Cookie Information.
2. Go to Consent solutions.
3. Find the consent solution to set the consent popup languages.
4. Go to Settings.
5. In General, add all necessary languages for your consent solution.
6. Click Save.
7. Create a script that detects the language code in the URL and adjusts the data culture.
Note: This works if your domain structure follows this format:
Here’s an example of such a script:
<!--<script type="text/javascript">
// Get the current URL
const currentUrl = window.location.href;
let languageCode = ""; // Check if the URL contains language codes
if (currentUrl.includes("/da")) {
languageCode = "DA";
} else if (currentUrl.includes("/no")) {
languageCode = "NO";
} else if (currentUrl.includes("/sv")) {
languageCode = "SV";
} else if (currentUrl.includes("/fi")) {
languageCode = "FI";
} else {
languageCode = "EN"; // Default to English
} // Set data-culture attribute based on the language code
document.getElementById("CookieConsent").setAttribute("data-culture", languageCode);
</script>-->
8. To use the script, update the language codes to match those on your domain.
9. Once the script is ready, add it directly to the source code of your website, above the Cookie Information main installation code.
10. Done.