Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect language from query params #160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
baseURL = "https://thorium.edrlab.org/"
title = "Thorium Reader"
# Language settings
contentDir = "content/en"
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true
# contentDir = "content/en"
# defaultContentLanguage = "en"
# defaultContentLanguageInSubdir = true
# Useful when translating.
enableMissingTranslationPlaceholders = true

Expand Down Expand Up @@ -62,6 +62,7 @@ blog = "/:section/:year/:month/:day/:slug/"
title = "Thorium Reader"
description = "The Reading Experience"
languageName ="English"
contentDir = "content/en"
# Weight used for sorting.
weight = 1
[languages.fr]
Expand Down
20 changes: 19 additions & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,22 @@
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
<!-- End Matomo Code -->

<script>
const params = new URLSearchParams(window.location.search);
const lang = params.get('lang');

if (lang) {
// Vérifiez si la langue est supportée
const supportedLanguages = ['en', 'fr', 'es'];
if (supportedLanguages.includes(lang)) {
const currentPath = window.location.pathname;
// Redirige vers le chemin correspondant à la langue
const newPath = `/${lang}${currentPath}`;
if (!window.location.pathname.startsWith(`/${lang}`)) {
window.location.href = newPath;
}
}
}
</script>