I'm working on a multilingual website in hugo using a multilingual-supported theme. I added the content in two languages and set the following two settings in the config file:
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true
I also specified the two languages as follows:
[languages]
[languages.en]
baseURL = "https://example.com/en"
weight = 100
[languages.nl]
baseURL = "https://example.com/nl"
When hugo generates the website, two directories are created as expected, one for each language. When I deploy the website, navigating to either of those urls send me to the website in the respective language. However, navigating to the base url example.com leads me nowhere because there is no html generated at that location.
I can implement this by bypassing hugo and manually adding an index.html at the site root:
<!DOCTYPE html>
<html lang="en-us">
<head>
<script type="text/javascript">
var languageCookie = getCookie("preferredLanguage")
if (languageCookie) {
var language = languageCookie
} else {
var language = navigator.language || navigator.userLanguage;
}
if (language == "nl") {
window.location.href = "https://example.app/nl"
document.cookie = "preferredLanguage=nl"
}
else {
window.location.href = "https://example.app/en"
}
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
</script>
</head>
</html>
But I rather have hugo generate this html. How can I specify a seperate page/javascript, that is language independent? Or is there another place where I can call this javascript? Any help is appreciated