forked from spacebar/spfn-website
Add Language Support and Copy English Translation as Placeholder
This commit is contained in:
parent
3c3f17fff6
commit
5be4b0e760
38 changed files with 1103 additions and 34 deletions
|
|
@ -1,26 +1,72 @@
|
|||
const guideContents = document.querySelectorAll(".guide-content");
|
||||
const guideButtons = document.querySelectorAll(".guide");
|
||||
const langs = [
|
||||
"en", // [x] English
|
||||
"es", // [ ] Spanish
|
||||
"ja", // [ ] Japanese
|
||||
"fr", // [ ] French
|
||||
"it", // [ ] Italian
|
||||
"de", // [ ] German
|
||||
]
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const guideParam = params.get("guide");
|
||||
async function updateGuide(guide, lang) {
|
||||
let buttonsRes = await fetch(`/md/${lang}/buttons.html`);
|
||||
|
||||
let guide = "install-wiiu";
|
||||
let guidePath = '/md/en/install-wiiu.md';
|
||||
if (guideParam) {
|
||||
guide = guideParam;
|
||||
guidePath = `/md/en/${guide}.md`;
|
||||
if (buttonsRes.ok) {
|
||||
let buttonsHTML = await buttonsRes.text();
|
||||
|
||||
document.getElementById("guide-buttons").innerHTML = buttonsHTML;
|
||||
}
|
||||
|
||||
let guidePath = `/md/${lang}/${guide}.md`;
|
||||
|
||||
let guideRes = await fetch(guidePath);
|
||||
|
||||
if (!guideRes.ok) throw new Error(`Guide "${guide}" was not found`);
|
||||
|
||||
const guideButton = document.getElementById(guide);
|
||||
if (guideButton) guideButton.classList.add("active");
|
||||
|
||||
let text = await guideRes.text();
|
||||
const html = marked.parse(text);
|
||||
document.getElementById("guide-contents").innerHTML = html;
|
||||
}
|
||||
|
||||
fetch(guidePath)
|
||||
.then(res => {
|
||||
if (!res.ok) throw new Error(`Guide "${guide} was not found`);
|
||||
|
||||
const guideButton = document.getElementById(guide);
|
||||
if (guideButton) guideButton.classList.add("active");
|
||||
async function updateLang(newLang) {
|
||||
localStorage.setItem("lang", newLang);
|
||||
|
||||
return res.text();
|
||||
})
|
||||
.then(text => {
|
||||
const html = marked.parse(text);
|
||||
document.getElementById("guide-contents").innerHTML = html;
|
||||
})
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const guideParam = params.get("guide");
|
||||
|
||||
let guide = "install-wiiu";
|
||||
if (guideParam) {
|
||||
guide = guideParam;
|
||||
}
|
||||
|
||||
await updateGuide(guide, newLang);
|
||||
}
|
||||
|
||||
window.onload = (async () => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const guideParam = params.get("guide");
|
||||
|
||||
let lang = "en"
|
||||
|
||||
let savedLang = localStorage.getItem("lang");
|
||||
|
||||
if (savedLang) {
|
||||
lang = savedLang;
|
||||
} else {
|
||||
let currentLang = navigator.language.split("-")[0];
|
||||
|
||||
if (langs.includes(currentLang)) {
|
||||
localStorage.setItem("lang", currentLang);
|
||||
lang = currentLang;
|
||||
}
|
||||
}
|
||||
|
||||
let guide = "install-wiiu";
|
||||
if (guideParam) {
|
||||
guide = guideParam;
|
||||
}
|
||||
|
||||
await updateGuide(guide, lang)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue