Skip to content

Commit a9a9ba6

Browse files
Merge pull request #1080 from andrea-kyurchiev/feat/redirect-to-default-languge
fix: redirect to English if translation doesnt exist
2 parents ce783fb + 5d0bcd1 commit a9a9ba6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

config/_default/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
baseURL: 'https://innersourcecommons.org/'
22
defaultContentLanguage: 'en'
33
defaultContentLanguageInSubdir: false
4+
params:
5+
# Redirect to default language if translation is missing
6+
redirectMissingTranslations: true
7+
48
title: InnerSource Commons
59

610
pluralizeListTitles: false

layouts/_default/baseof.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,29 @@
99
{{- partial "footer.html" . -}}
1010
</body>
1111

12+
{{ if not .Content }}
13+
{{ if .Site.Params.redirectMissingTranslations }}
14+
<script>
15+
const path = window.location.pathname;
16+
const pathParts = path.split('/');
17+
const currentLang = pathParts[1];
18+
19+
// If not English, try English version
20+
if (currentLang !== 'en' && currentLang.length === 2) {
21+
const englishPath = path.replace(`/${currentLang}/`, '/en/');
22+
23+
// Check if English version exists (you'd need to implement this check)
24+
fetch(englishPath)
25+
.then(response => {
26+
if (response.ok) {
27+
window.location.href = englishPath;
28+
}
29+
})
30+
.catch(() => {
31+
// Show 404 page
32+
});
33+
}
34+
</script>
35+
{{ end }}
36+
{{ end }}
1237
</html>

0 commit comments

Comments
 (0)