mirror of
https://github.com/MPSU/APS.git
synced 2026-06-10 11:13:33 +00:00
WIP: сборка английской версии mdbook
This commit is contained in:
44
.github/theme/language-switcher.css
vendored
Normal file
44
.github/theme/language-switcher.css
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ── Language Switcher ───────────────────────────────────────────────────── */
|
||||
|
||||
#language-switcher {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
background: none;
|
||||
border: 1px solid var(--icons);
|
||||
border-radius: 4px;
|
||||
color: var(--icons);
|
||||
cursor: pointer;
|
||||
font-size: 0.82em;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
padding: 3px 8px;
|
||||
|
||||
/* sit nicely alongside the existing icon buttons */
|
||||
margin-right: 4px;
|
||||
vertical-align: middle;
|
||||
|
||||
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
||||
}
|
||||
|
||||
#language-switcher:hover,
|
||||
#language-switcher:focus-visible {
|
||||
color: var(--icons-hover);
|
||||
border-color: var(--icons-hover);
|
||||
background-color: rgba(128, 128, 128, 0.08);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Keep the flag emoji from being shrunk by the parent flex layout */
|
||||
#language-switcher span[aria-hidden] {
|
||||
font-size: 1.1em;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Hide text label on very small screens, show only flag */
|
||||
@media (max-width: 420px) {
|
||||
#language-switcher .lang-label {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
63
.github/theme/language-switcher.js
vendored
Normal file
63
.github/theme/language-switcher.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// Detects current language from the URL path.
|
||||
// Russian lives at /APS/... English lives at /APS/en/...
|
||||
function currentLang() {
|
||||
return /\/en\//.test(window.location.pathname) ? "en" : "ru";
|
||||
}
|
||||
|
||||
function switchLanguage() {
|
||||
var path = window.location.pathname;
|
||||
var newPath;
|
||||
|
||||
if (currentLang() === "en") {
|
||||
// /APS/en/foo/bar.html → /APS/foo/bar.html
|
||||
newPath = path.replace("/en/", "/");
|
||||
} else {
|
||||
// /APS/foo/bar.html → /APS/en/foo/bar.html
|
||||
// Insert "en/" after the first path segment (the repo root, e.g. /APS/)
|
||||
newPath = path.replace(/^(\/[^\/]+\/)/, "$1en/");
|
||||
}
|
||||
|
||||
window.location.href =
|
||||
newPath + window.location.search + window.location.hash;
|
||||
}
|
||||
|
||||
function addSwitcher() {
|
||||
var lang = currentLang();
|
||||
|
||||
var btn = document.createElement("button");
|
||||
btn.id = "language-switcher";
|
||||
btn.setAttribute(
|
||||
"title",
|
||||
lang === "ru" ? "Switch to English" : "Переключить на русский"
|
||||
);
|
||||
btn.setAttribute("aria-label", btn.getAttribute("title"));
|
||||
|
||||
// Flag + label
|
||||
var icon = document.createElement("span");
|
||||
icon.setAttribute("aria-hidden", "true");
|
||||
icon.textContent = lang === "ru" ? "🇬🇧" : "🇷🇺";
|
||||
|
||||
var label = document.createElement("span");
|
||||
label.className = "lang-label";
|
||||
label.textContent = lang === "ru" ? "EN" : "RU";
|
||||
|
||||
btn.appendChild(icon);
|
||||
btn.appendChild(label);
|
||||
btn.addEventListener("click", switchLanguage);
|
||||
|
||||
// mdBook places theme/print/search buttons in .right-buttons
|
||||
var target = document.querySelector(".right-buttons");
|
||||
if (target) {
|
||||
target.insertBefore(btn, target.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", addSwitcher);
|
||||
} else {
|
||||
addSwitcher();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user