# -*- coding: utf-8 -*- """Replace the nav's text language switch with the globe on every page (2026-10-08 ruling: a globe with a list of languages, matching the controller). One language list; each page's own URL and its twins' URLs.""" import io, os, re, sys W = "/mnt/5_hdd/felhom.eu/git/felhom.eu/website" LANGS = [("hu", "Magyar"), ("en", "English")] # order on every page LABEL = {"hu": "Nyelv", "en": "Language"} # page -> {lang: url}; NO_TWIN pages point their foreign item at the other language's home SETS = [("index.html", "/", "en/index.html", "/en/"), ("alkalmazasok.html", "/alkalmazasok", "en/apps.html", "/en/apps"), ("technologiak.html", "/technologiak", "en/technology.html", "/en/technology"), ("biztonsagimentes.html", "/biztonsagimentes", "en/backups.html", "/en/backups"), ("gyik.html", "/gyik", "en/faq.html", "/en/faq"), ("kapcsolat.html", "/kapcsolat", "en/contact.html", "/en/contact"), ("letoltes.html", "/letoltes", "en/download.html", "/en/download")] PAGES = {} for hu, hu_u, en, en_u in SETS: PAGES[hu] = ("hu", {"hu": hu_u, "en": en_u}) PAGES[en] = ("en", {"hu": hu_u, "en": en_u}) PAGES["404.html"] = ("hu", {"hu": "/", "en": "/en/"}) PAGES["szolgaltatasok-nonpublic.html"] = ("hu", {"hu": "/szolgaltatasok-nonpublic", "en": "/en/"}) def globe(lang, urls): items = [] for code, name in LANGS: cur = code == lang items.append('
  • %s
  • ' % (urls[code], code, code, " current" if cur else "", ' aria-current="true"' if cur else "", name)) return ('
  • ' '' '
  • ') % (LABEL[lang], LABEL[lang], "".join(items)) SW = re.compile(r'
  • [^<]*
  • ') for p, (lang, urls) in PAGES.items(): path = os.path.join(W, p) s = io.open(path, encoding="utf-8-sig").read() s, n = SW.subn(lambda m: globe(lang, urls), s) assert n == 1, (p, n) s, k = re.subn(r"/assets/site\.css\?v=2\b", "/assets/site.css?v=3", s) assert k == 1, (p, k) with io.open(path, "w", encoding="utf-8-sig", newline="\n") as f: f.write(s) print(p, "globe + css v3")