mirror of
https://github.com/rvtr/wiki.git
synced 2025-10-31 06:31:13 -04:00
Force language alert to correct direction
This commit is contained in:
parent
97389697d7
commit
ff7c321f0b
@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="alert alert-secondary alert-dismissible fade language-alert show d-none mt-3 mb-0" role="alert">
|
||||
<div id="language-alert" class="alert alert-secondary alert-dismissible fade show d-none mt-3 mb-0" role="alert">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -367,6 +367,14 @@ kbd.face {
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.direction-ltr {
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.direction-rtl {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 576px) {
|
||||
// Version of .position-absolute that only triggers for sm+
|
||||
.position-absolute-sm {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const languages = [ "da-DK", "de-DE", "en-US", "es-ES", "fr-FR", "hu-HU", "ic-IC", "it-IT", "ja-JP", "ko-KR", "no-NO", "pl-PL", "pt-PT", "ru-RU", "sv-SE", "tr-TR", "uk-UA", "zh-CN", "zh-TW" ];
|
||||
const languages = ["da-DK", "de-DE", "en-US", "es-ES", "fr-FR", "hu-HU", "he-IL", "ic-IC", "it-IT", "ja-JP", "ko-KR", "no-NO", "pl-PL", "pt-PT", "ru-RU", "sv-SE", "tr-TR", "uk-UA", "zh-CN", "zh-TW"];
|
||||
const rtl = ["he-IL"];
|
||||
let languageID = document.documentElement.lang == "ic-IC" ? document.documentElement.lang : `${window.navigator.language.substr(0, 2)}-${window.navigator.language.substr(3, 3).toUpperCase()}`;
|
||||
if(!languages.includes(languageID)) {
|
||||
languageID = languages.filter(r => r.includes(languageID))?.[0];
|
||||
@ -6,20 +7,19 @@ if(!languages.includes(languageID)) {
|
||||
|
||||
|
||||
if(languageID) {
|
||||
top:
|
||||
for(let language of document.getElementById("language-dropdown").children) {
|
||||
if((language.children[0].dataset.languageId == languageID && !language.children[0].classList.contains("active")) || languageID == "ic-IC") {
|
||||
for(let languageAlert of document.getElementsByClassName("language-alert")) {
|
||||
languageAlert.classList.remove("d-none");
|
||||
let a = document.createElement("a");
|
||||
a.href = `${languageID == "en-US" ? "" : ("/" + languageID)}${window.location.pathname.replace(/[a-z][a-z]-[A-Z][A-Z]\//, "")}`;
|
||||
languageAlert.prepend(a);
|
||||
|
||||
import(`./i18n/${languageID}.js`).then(obj => {
|
||||
a.innerHTML = obj.default.pageIsInYourLanguage;
|
||||
}).catch(() => a.innerHTML = "This page is available in your language!");
|
||||
break top;
|
||||
}
|
||||
let languageAlert = document.getElementById("language-alert");
|
||||
languageAlert.classList.remove("d-none");
|
||||
languageAlert.classList.add(rtl.includes(languageID) ? "direction-rtl" : "direction-ltr");
|
||||
let a = document.createElement("a");
|
||||
a.href = `${languageID == "en-US" ? "" : ("/" + languageID)}${window.location.pathname.replace(/[a-z][a-z]-[A-Z][A-Z]\//, "")}`;
|
||||
languageAlert.prepend(a);
|
||||
|
||||
import(`./i18n/${languageID}.js`).then(obj => {
|
||||
a.innerHTML = obj.default.pageIsInYourLanguage;
|
||||
}).catch(() => a.innerHTML = "This page is available in your language!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user