/* nav-i18n.js — IOUNet navigation internationalisation Include on every page: Detects language from: URL path prefix, localStorage, or lang picker click. Translates nav labels + updates links to language-specific pages where they exist. */ (function(){ // === TRANSLATION TABLE === var T = { fr: { label: 'FR', nav: { 'Home': 'Accueil', 'Start Here': 'Commencer ici', 'IOU Demo': 'D\u00e9mo IOU', 'Planetary \u2014 10 Billion': 'Plan\u00e9taire \u2014 10 milliards', 'Community \u2014 Live': 'Communaut\u00e9 \u2014 En direct', 'The Principle': 'Le Principe', 'Money as Debt': "L'argent est une dette", 'AI & Robots': 'IA & Robots', 'Jubilee 2026': 'Jubil\u00e9 2026', 'History': 'Histoire', 'Ancient Jubilees': 'Jubil\u00e9s antiques', 'The Usury Ban': "L'interdiction de l'usure", 'Tally Sticks & the Burning of Parliament': 'B\u00e2tons de comptage', 'The Bank of England': "La Banque d'Angleterre", 'The Camel & the Needle':'Le chameau & le chas de l\'aiguille', 'Marketplace': 'March\u00e9', 'FAQ': 'FAQ', 'Roadmap': 'Feuille de route', 'Join IOUNet': 'Rejoindre IOUNet', 'Login': 'Connexion', 'Groups Tutorial': 'Tutoriel Groupes', 'Marketplace Explorer': 'Explorateur du march\u00e9', 'Community Engine': 'Moteur communautaire', 'Planetary Engine': 'Moteur plan\u00e9taire' }, // Pages that have a French version: english path -> french path pages: { '/': '/fr', '/start': '/start_fr', '/faq': '/faq_fr', '/marketplace': '/marketplace_fr', '/roadmap': '/roadmap_fr' } }, de: { label: 'DE', nav: { 'Home': 'Startseite', 'Start Here': 'Hier starten', 'IOU Demo': 'IOU Demo', 'Planetary \u2014 10 Billion': 'Planet\u00e4r \u2014 10 Milliarden', 'Community \u2014 Live': 'Gemeinschaft \u2014 Live', 'The Principle': 'Das Prinzip', 'Money as Debt': 'Geld als Schuld', 'AI & Robots': 'KI & Roboter', 'Jubilee 2026': 'Jubil\u00e4um 2026', 'History': 'Geschichte', 'Ancient Jubilees': 'Antike Jubil\u00e4en', 'The Usury Ban': 'Das Wucherverbot', 'Tally Sticks & the Burning of Parliament': 'Kerbh\u00f6lzer', 'The Bank of England': 'Die Bank von England', 'The Camel & the Needle':'Das Kamel & das Nadel\u00f6hr', 'Marketplace': 'Marktplatz', 'FAQ': 'FAQ', 'Roadmap': 'Fahrplan', 'Join IOUNet': 'IOUNet beitreten', 'Login': 'Anmelden' }, pages: { '/': '/de', '/faq': '/faq_de' } }, es: { label: 'ES', nav: { 'Home': 'Inicio', 'Start Here': 'Empieza aqu\u00ed', 'IOU Demo': 'Demo IOU', 'Planetary \u2014 10 Billion': 'Planetario \u2014 10 mil millones', 'Community \u2014 Live': 'Comunidad \u2014 En vivo', 'The Principle': 'El Principio', 'Money as Debt': 'El dinero como deuda', 'AI & Robots': 'IA y Robots', 'Jubilee 2026': 'Jubileo 2026', 'History': 'Historia', 'Ancient Jubilees': 'Jubileos antiguos', 'The Usury Ban': 'La prohibici\u00f3n de la usura', 'Tally Sticks & the Burning of Parliament': 'Palos de conteo', 'The Bank of England': 'El Banco de Inglaterra', 'The Camel & the Needle':'El camello y el ojo de la aguja', 'Marketplace': 'Mercado', 'FAQ': 'FAQ', 'Roadmap': 'Hoja de ruta', 'Join IOUNet': 'Unirse a IOUNet', 'Login': 'Iniciar sesi\u00f3n' }, pages: { '/': '/es', '/faq': '/faq_es' } }, it: { label: 'IT', nav: { 'Home': 'Home', 'Start Here': 'Inizia qui', 'IOU Demo': 'Demo IOU', 'Planetary \u2014 10 Billion': 'Planetario \u2014 10 miliardi', 'Community \u2014 Live': 'Comunit\u00e0 \u2014 In diretta', 'The Principle': 'Il Principio', 'Money as Debt': 'Il denaro come debito', 'AI & Robots': 'IA e Robot', 'Jubilee 2026': 'Giubileo 2026', 'History': 'Storia', 'Ancient Jubilees': 'Giubilei antichi', 'The Usury Ban': "Il divieto dell'usura", 'Tally Sticks & the Burning of Parliament': 'Bastoni di conteggio', 'The Bank of England': "La Banca d'Inghilterra", 'The Camel & the Needle':'Il cammello e la cruna dell\'ago', 'Marketplace': 'Mercato', 'FAQ': 'FAQ', 'Roadmap': 'Tabella di marcia', 'Join IOUNet': 'Unisciti a IOUNet', 'Login': 'Accedi' }, pages: { '/': '/it', '/faq': '/faq_it' } }, pt: { label: 'PT', nav: { 'Home': 'In\u00edcio', 'Start Here': 'Comece aqui', 'IOU Demo': 'Demo IOU', 'Planetary \u2014 10 Billion': 'Planet\u00e1rio \u2014 10 bilh\u00f5es', 'Community \u2014 Live': 'Comunidade \u2014 Ao vivo', 'The Principle': 'O Princ\u00edpio', 'Money as Debt': 'Dinheiro como d\u00edvida', 'AI & Robots': 'IA e Rob\u00f4s', 'Jubilee 2026': 'Jubileu 2026', 'History': 'Hist\u00f3ria', 'Ancient Jubilees': 'Jubileus antigos', 'The Usury Ban': 'A proibi\u00e7\u00e3o da usura', 'Tally Sticks & the Burning of Parliament': 'Bast\u00f5es de contagem', 'The Bank of England': 'O Banco da Inglaterra', 'The Camel & the Needle':'O camelo e o buraco da agulha', 'Marketplace': 'Mercado', 'FAQ': 'FAQ', 'Roadmap': 'Roteiro', 'Join IOUNet': 'Junte-se ao IOUNet', 'Login': 'Entrar' }, pages: { '/': '/pt', '/faq': '/faq_pt' } }, zh: { label: '\u4E2D\u6587', nav: { 'Home': '\u9996\u9875', 'Start Here': '\u4ECE\u8FD9\u91CC\u5F00\u59CB', 'IOU Demo': 'IOU \u6F14\u793A', 'Planetary \u2014 10 Billion': '\u884C\u661F\u7EA7 \u2014 100\u4EBF', 'Community \u2014 Live': '\u793E\u533A \u2014 \u5B9E\u65F6', 'The Principle': '\u539F\u7406', 'Marketplace': '\u5E02\u573A', 'FAQ': '\u5E38\u89C1\u95EE\u9898', 'Roadmap': '\u8DEF\u7EBF\u56FE', 'Join IOUNet': '\u52A0\u5165 IOUNet', 'Login': '\u767B\u5F55' }, pages: { '/': '/zh', '/faq': '/faq_zh' } }, hi: { label: '\u0939\u093F\u0928\u094D\u0926\u0940', nav: { 'Home': '\u0939\u094B\u092E', 'Start Here': '\u092F\u0939\u093E\u0901 \u0936\u0941\u0930\u0942 \u0915\u0930\u0947\u0902', 'IOU Demo': 'IOU \u0921\u0947\u092E\u094B', 'Marketplace': '\u092C\u093E\u091C\u093C\u093E\u0930', 'FAQ': 'FAQ', 'Join IOUNet': 'IOUNet \u092E\u0947\u0902 \u0936\u093E\u092E\u093F\u0932 \u0939\u094B\u0902', 'Login': '\u0932\u0949\u0917\u093F\u0928' }, pages: { '/': '/hi', '/faq': '/faq_hi' } }, ar: { label: '\u0627\u0644\u0639\u0631\u0628\u064A\u0629', nav: { 'Home': '\u0627\u0644\u0631\u0626\u064A\u0633\u064A\u0629', 'Start Here': '\u0627\u0628\u062F\u0623 \u0647\u0646\u0627', 'IOU Demo': '\u0639\u0631\u0636 IOU', 'Marketplace': '\u0627\u0644\u0633\u0648\u0642', 'FAQ': '\u0623\u0633\u0626\u0644\u0629 \u0634\u0627\u0626\u0639\u0629', 'Join IOUNet': '\u0627\u0646\u0636\u0645 \u0625\u0644\u0649 IOUNet', 'Login': '\u062A\u0633\u062C\u064A\u0644 \u0627\u0644\u062F\u062E\u0648\u0644' }, pages: { '/': '/ar', '/faq': '/faq_ar' } }, ru: { label: '\u0420\u0443\u0441\u0441\u043A\u0438\u0439', nav: { 'Home': '\u0413\u043B\u0430\u0432\u043D\u0430\u044F', 'Start Here': '\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044C', 'IOU Demo': '\u0414\u0435\u043C\u043E IOU', 'Marketplace': '\u0420\u044B\u043D\u043E\u043A', 'FAQ': '\u0427\u0430\u0412\u041E', 'Join IOUNet': '\u041F\u0440\u0438\u0441\u043E\u0435\u0434\u0438\u043D\u0438\u0442\u044C\u0441\u044F', 'Login': '\u0412\u043E\u0439\u0442\u0438' }, pages: { '/': '/ru', '/faq': '/faq_ru' } }, ja: { label: '\u65E5\u672C\u8A9E', nav: { 'Home': '\u30DB\u30FC\u30E0', 'Start Here': '\u3053\u3053\u304B\u3089\u59CB\u3081\u308B', 'IOU Demo': 'IOU \u30C7\u30E2', 'Marketplace': '\u30DE\u30FC\u30B1\u30C3\u30C8', 'FAQ': '\u3088\u304F\u3042\u308B\u8CEA\u554F', 'Join IOUNet': 'IOUNet\u306B\u53C2\u52A0', 'Login': '\u30ED\u30B0\u30A4\u30F3' }, pages: { '/': '/ja', '/faq': '/faq_ja' } }, sw: { label: 'Kiswahili', nav: { 'Home': 'Nyumbani', 'Start Here': 'Anza hapa', 'IOU Demo': 'Onyesho la IOU', 'Marketplace': 'Soko', 'FAQ': 'Maswali', 'Join IOUNet': 'Jiunge na IOUNet', 'Login': 'Ingia' }, pages: { '/': '/sw', '/faq': '/faq_sw' } } }; // === DETECT LANGUAGE === function detectLang() { // 1. Check URL — pages that are already language-specific var path = window.location.pathname; // Match /fr, /fr/, /start_fr, /faq_fr etc. var urlMatch = path.match(/^\/([a-z]{2})(?:\/|$)/) || path.match(/[_]([a-z]{2})(?:\.html)?$/); if (urlMatch && T[urlMatch[1]]) { localStorage.setItem('iounet_lang', urlMatch[1]); return urlMatch[1]; } // 2. Check localStorage var stored = localStorage.getItem('iounet_lang'); if (stored && T[stored]) return stored; // 3. Default: English (no translation needed) return 'en'; } // === TRANSLATE NAV === function translateNav(lang) { if (lang === 'en' || !T[lang]) return; var tr = T[lang]; // Translate nav dropdown links and sub-menu links var links = document.querySelectorAll('.nav-dropdown a, .nav-sub-menu a, .nav-sub-label'); links.forEach(function(el) { // Extract text after emoji (emoji is typically first 1-3 chars + space) var text = el.textContent || el.innerText; // Try to match the English label part (after emoji prefix) var match = text.match(/^([\s\S]*?(?:[\u{1F000}-\u{1FFFF}][\uFE0F]?\s*)+)(.+)$/u); var emoji = '', label = text; if (match) { emoji = match[1]; label = match[2].trim(); } // Handle mdash in labels label = label.replace(/\s*\u2014\s*/g, ' \u2014 ').trim(); if (tr.nav[label]) { if (emoji) { el.textContent = emoji + tr.nav[label]; } else { el.textContent = tr.nav[label]; } } }); // Update nav links to point to translated pages where available if (tr.pages) { var allLinks = document.querySelectorAll('.nav-dropdown a, .nav-sub-menu a'); allLinks.forEach(function(a) { var href = a.getAttribute('href'); if (href && tr.pages[href]) { a.setAttribute('href', tr.pages[href]); } // Add ?lang= to planetary links so language preference travels across subdomains if (href && href.indexOf('planetary.iou-net.org') !== -1 && href.indexOf('lang=') === -1) { a.setAttribute('href', href + (href.indexOf('?') === -1 ? '?' : '&') + 'lang=' + lang); } }); } // Update logo link to language-specific homepage var logo = document.querySelector('.nav-logo'); if (logo && tr.pages['/']) { logo.setAttribute('href', tr.pages['/']); } // Update language picker button text var langBtn = document.querySelector('.lang-btn'); if (langBtn) { langBtn.textContent = '\uD83C\uDF10 ' + tr.label + ' \u25BE'; } // Update active state in language menu var langLinks = document.querySelectorAll('.lang-menu a'); langLinks.forEach(function(a) { a.classList.remove('active'); var href = a.getAttribute('href'); if (href) { // Check if this lang menu item corresponds to current language var m = href.match(/^\/([a-z]{2})(?:\/|$)/) || href.match(/[_]([a-z]{2})(?:$)/); if (m && m[1] === lang) a.classList.add('active'); // English special case if (lang === 'en' && (href === '/' || href === '/start')) a.classList.add('active'); } }); } // === LANGUAGE PICKER HANDLER === // Intercept lang picker clicks to store preference function setupLangPicker() { var langLinks = document.querySelectorAll('.lang-menu a'); langLinks.forEach(function(a) { a.addEventListener('click', function() { var href = a.getAttribute('href'); if (!href) return; // Detect language from the link var m = href.match(/^\/([a-z]{2})(?:\/|$)/) || href.match(/[_]([a-z]{2})(?:$)/); if (m && T[m[1]]) { localStorage.setItem('iounet_lang', m[1]); } else if (href === '/' || href === '/start') { localStorage.setItem('iounet_lang', 'en'); } }); }); } // === AUTO-REDIRECT to translated page if available === function autoRedirect(lang) { if (lang === 'en' || !T[lang] || !T[lang].pages) return; var path = window.location.pathname; var target = T[lang].pages[path]; if (target && target !== path) { window.location.replace(target); return true; } return false; } // === RUN === var lang = detectLang(); if (lang !== 'en') { // Redirect to translated page if one exists (before DOM work) if (autoRedirect(lang)) return; // Small delay to ensure DOM is ready (script may be in ) if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { translateNav(lang); setupLangPicker(); }); } else { translateNav(lang); setupLangPicker(); } } else { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', setupLangPicker); } else { setupLangPicker(); } } })();