Files
ProcessControl/_i18n-switcher.html
MatsuneMikuroiandClaude Opus 5 f7fa60ba81 Night-mode styling, French cross-references, and the log through Part VI
- theme.scss and figures draw with the extension's --calc-… tokens; light/dark
  pair plus the high-contrast button; a11y highlight style for html
- figure labels split so none leaves its viewBox in any language
- _quarto-fr.yml: French cross-reference prefixes
- notes extension synced to 2.8.18
- conv/: Parts IV, V and VI logged, pasted terminal output redacted

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-06 03:36:51 +02:00

125 lines
5.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- Language switcher for the html output only (included in the <head>).
Each profile's sidebar translate menu links to the start page of the other
languages (_book/ English, _book/fr/, _book/de/). All three books share the
same file names and section ids (#sec-...), so a click is sent to the same
page and section of the other language instead.
Quarto's page scripts rewrite those links in the browser (to an absolute
address without index.html), and can do so after this script runs. So
nothing is attached to the links themselves: one capture-phase listener on
the document reads the link's final address at click time.
If a language has not been built, its pages do not exist:
the target is checked first and a short note is shown instead of a
"Not Found" page.
The language picked in the menu is remembered for a year in a cookie
(notes-lang, limited to the book's address). A later visit to a page in
another language goes straight to the same page in the remembered one; this
runs in the <head>, before anything is drawn. Not in the local preview
(file:, localhost), where the other languages may not be built. -->
<script>
(function () {
var CODE = { 'Deutsch': 'de', 'Français': 'fr', 'English': 'en' };
var ROOT_LANG = 'en'; // the language at the top of _book/
var COOKIE = 'notes-lang';
var NOTE = {
de: 'Diese Sprache ist hier noch nicht verfügbar.',
fr: 'Cette langue n’est pas encore disponible ici.',
en: 'This language is not available here yet.'
};
var here = (document.documentElement.lang || ROOT_LANG).slice(0, 2);
// the book's top folder: /…/fr/page.html -> /…/ ; /…/page.html -> /…/
var dir = location.pathname.replace(/[^\/]*$/, '');
var root = (here !== ROOT_LANG && dir.slice(-(here.length + 2)) === '/' + here + '/')
? dir.slice(0, -(here.length + 1)) : dir;
var page = location.pathname.slice(dir.length); // "" for a folder
function remembered() {
var m = document.cookie.match(/(?:^|;\s*)notes-lang=(de|fr|en)(?:;|$)/);
return m ? m[1] : null;
}
// path '/' on purpose: every book of these notes is served from one host,
// each under its own folder, so a language picked in any of them is the
// language all of them open in. A book hosted on its own would be no worse
// off -- the cookie simply has nothing else to reach.
var COOKIE_PATH = '/';
function remember(code) {
document.cookie = COOKIE + '=' + code + '; path=' + COOKIE_PATH
+ '; max-age=31536000; SameSite=Lax'
+ (location.protocol === 'https:' ? '; Secure' : '');
// a copy written under the book's own path by an earlier version would be
// the more specific one and would shadow the shared cookie for good
if (root !== COOKIE_PATH) {
document.cookie = COOKIE + '=; path=' + root + '; max-age=0';
}
}
// a returning reader lands in the language picked last time
var live = /^https?:$/.test(location.protocol)
&& !/^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname);
var wanted = remembered();
if (live && wanted && wanted !== here) {
location.replace(root + (wanted === ROOT_LANG ? '' : wanted + '/') + page
+ location.search + location.hash);
return;
}
function note() {
var lang = (document.documentElement.lang || 'en').slice(0, 2);
var box = document.createElement('div');
box.setAttribute('role', 'status');
box.className = 'i18n-note';
box.textContent = NOTE[lang] || NOTE.en;
box.style.cssText = 'position:fixed;left:50%;bottom:1.25rem;transform:translateX(-50%);'
+ 'max-width:min(34rem,calc(100vw - 2rem));padding:.6rem .9rem;border-radius:6px;'
+ 'background:#1f2328;color:#fff;font-size:.85rem;line-height:1.4;z-index:2000;'
// a status message, so it keeps its own dark surface in either mode; the
// hairline is the page's rule colour, invisible on a light page and an
// edge against a dark one, where the shadow alone no longer separates it
+ 'border:1px solid var(--calc-line,#444);'
+ 'box-shadow:0 4px 16px var(--calc-shadow,rgba(0,0,0,.25))';
document.body.appendChild(box);
setTimeout(function () { box.remove(); }, 7000);
}
function exists(url) {
return fetch(url, { method: 'HEAD', cache: 'no-store' })
.then(function (r) { return r.status !== 404; }, function () { return true; });
}
document.addEventListener('click', function (ev) {
if (ev.button !== 0 || ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
var a = ev.target.closest && ev.target.closest('a.sidebar-tools-main-item');
if (!a || !a.href) return;
var code = CODE[a.textContent.trim()];
if (!code) return; // some other tool link
ev.preventDefault();
// the language being read already: just remember it
if (code === here) { remember(code); return; }
var link = new URL(a.href, location.href);
var target_root = link.pathname.replace(/index\.html$/, ''); // "/" or "/fr/"
if (target_root.slice(-1) !== '/') target_root += '/';
var target = link.origin + target_root + (page || 'index.html');
if (location.protocol === 'file:' || !window.fetch) {
remember(code);
location.href = target + location.hash;
return;
}
// same page in the other language, else its start page, else explain
exists(target).then(function (ok) {
if (ok) { remember(code); location.href = target + location.hash; return; }
return exists(link.origin + target_root).then(function (rootOk) {
if (rootOk) { remember(code); location.href = link.origin + target_root; }
else note();
});
});
}, true);
})();
</script>