mirror of
https://github.com/rvtr/wiki.git
synced 2025-10-31 06:31:13 -04:00
Add this page is available in [your languge] alert
This commit is contained in:
parent
92734ed05b
commit
6f935161c2
@ -1 +1,2 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
|
||||
<script src="/assets/js/language-alert.js" type="module"></script>
|
||||
|
||||
5
_includes/language-alert.html
Normal file
5
_includes/language-alert.html
Normal file
@ -0,0 +1,5 @@
|
||||
<div class="row">
|
||||
<div class="alert alert-primary alert-dismissible fade language-alert show d-none rounded-0" role="alert">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
@ -39,13 +39,13 @@
|
||||
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 0 0 5.145 4H7.5V1.077zM4.09 4H2.255a7.025 7.025 0 0 1 3.072-2.472 6.7 6.7 0 0 0-.597.933c-.247.464-.462.98-.64 1.539zm-.582 3.5h-2.49c.062-.89.291-1.733.656-2.5H3.82a13.652 13.652 0 0 0-.312 2.5zM4.847 5H7.5v2.5H4.51A12.5 12.5 0 0 1 4.846 5zM8.5 5v2.5h2.99a12.495 12.495 0 0 0-.337-2.5H8.5zM4.51 8.5H7.5V11H4.847a12.5 12.5 0 0 1-.338-2.5zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12H7.5v2.923c-.67-.204-1.335-.82-1.887-1.855A7.97 7.97 0 0 1 5.145 12zm.182 2.472a6.696 6.696 0 0 1-.597-.933A9.268 9.268 0 0 1 4.09 12H2.255a7.024 7.024 0 0 0 3.072 2.472zM3.82 11H1.674a6.958 6.958 0 0 1-.656-2.5h2.49c.03.877.138 1.718.312 2.5zm6.853 3.472A7.024 7.024 0 0 0 13.745 12H11.91a9.27 9.27 0 0 1-.64 1.539 6.688 6.688 0 0 1-.597.933zM8.5 12h2.355a7.967 7.967 0 0 1-.468 1.068c-.552 1.035-1.218 1.65-1.887 1.855V12zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.65 13.65 0 0 1-.312 2.5zm2.802-3.5h-2.49A13.65 13.65 0 0 0 12.18 5h2.146c.365.767.594 1.61.656 2.5zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7.024 7.024 0 0 0-3.072-2.472c.218.284.418.598.597.933zM10.855 4H8.5V1.077c.67.204 1.335.82 1.887 1.855.173.324.33.682.468 1.068z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end-sm">
|
||||
<ul class="dropdown-menu dropdown-menu-end-sm" id="language-dropdown">
|
||||
{% assign ref = page.url | split: page.collection | last %}
|
||||
{% for collection in site.collections %}
|
||||
{% for item in site[collection.label] %}
|
||||
{% assign itemRef = item.url | split: item.lang | last %}
|
||||
{% if itemRef == ref %}
|
||||
<li><a class="dropdown-item{% if item.lang == page.collection %} active {% endif %}" href="{{ item.url }}">{{ site.lang-names[item.lang] }}</a></li>
|
||||
<li><a class="dropdown-item{% if item.lang == page.collection %} active{% endif %}" data-language-id="{{ item.lang }}" href="{{ item.url }}">{{ site.lang-names[item.lang] }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
@ -12,6 +12,7 @@ layout: compress
|
||||
|
||||
<main>
|
||||
<div class="container-fluid">
|
||||
{% include language-alert.html %}
|
||||
<div class="row pt-5">
|
||||
<div class="col-sm-2"></div>
|
||||
<div class="col-sm-8">
|
||||
|
||||
@ -12,6 +12,7 @@ layout: compress
|
||||
|
||||
<main>
|
||||
<div class="container-fluid">
|
||||
{% include language-alert.html %}
|
||||
<div class="row pt-5">
|
||||
<div class="col-md-1"></div>
|
||||
<div class="col-md-3">
|
||||
|
||||
3
assets/js/i18n/en-US.js
Normal file
3
assets/js/i18n/en-US.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
"pageIsInYourLanguage": "This page is available in English!"
|
||||
}
|
||||
25
assets/js/language-alert.js
Normal file
25
assets/js/language-alert.js
Normal file
@ -0,0 +1,25 @@
|
||||
const languages = [ "da-DK", "de-DE", "en-US", "es-ES", "fr-FR", "hu-HU", "it-IT", "ja-JP", "ko-KR", "no-NO", "pl-PL", "pt-PT", "ru-RU", "sv-SE", "tr-TR", "uk-UA", "zh-CN", "zh-TW" ];
|
||||
let languageID = `${window.navigator.language.substr(0, 2)}-${window.navigator.language.substr(3, 3).toUpperCase()}`
|
||||
if(!languageID.match(/[a-z][a-z]-[A-Z][A-Z]/)) {
|
||||
languageID = languages.filter(r => r.includes(languageID))?.[0];
|
||||
}
|
||||
|
||||
if(languageID) {
|
||||
for(let language of document.getElementById("language-dropdown").children) {
|
||||
if(language.children[0].dataset.languageId == languageID && !language.children[0].classList.contains("active")) {
|
||||
console.log(languageID)
|
||||
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]\//, "")}`;
|
||||
console.log(a.href);
|
||||
languageAlert.prepend(a);
|
||||
|
||||
import(`./i18n/${languageID}.js`).then(obj => {
|
||||
a.innerHTML = obj.default.pageIsInYourLanguage;
|
||||
}).catch((err) => {console.log(err); a.innerHTML = "This page is available in your language!"});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,3 +7,5 @@ files:
|
||||
translation: /pages/_%locale%/**/%original_file_name%
|
||||
- source: /_data/en-US/**/*.json
|
||||
translation: /_data/%locale%/**/%original_file_name%
|
||||
- source: /assets/js/i18n/en-US.js
|
||||
translation: /assets/js/i18n/%locale%.js
|
||||
|
||||
Loading…
Reference in New Issue
Block a user