Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(i18n): translate the global nav and getting-started shell
nirholas5501dd15d646
diff --git a/public/getting-started.js b/public/getting-started.jsindex a06ce930c..4d93f020e 100644--- a/public/getting-started.js+++ b/public/getting-started.js@@ -127,12 +127,31 @@}// ── DOM utilities ────────────────────────────────────────────────────────────+ // i18n key for a shell string — must match nav-data.js navKey and the offline+ // harvester (scripts/i18n-nav-harvest.mjs) so the runtime (src/i18n.js) swaps+ // these labels per locale.+ function navKey(text) {+ var s = String(text == null ? '' : text);+ var h = 0x811c9dc5;+ for (var i = 0; i < s.length; i++) {+ h ^= s.charCodeAt(i);+ h = Math.imul(h, 0x01000193);+ }+ return 'nav.' + (h >>> 0).toString(36);+ }function el(tag, cls, text) {var n = document.createElement(tag);if (cls) n.className = cls;if (text != null) n.textContent = text;return n;}+ // el() variant that tags the element for translation (static labels only —+ // never dynamic text like counts or the ✓/glyph marks).+ function elT(tag, cls, text) {+ var n = el(tag, cls, text);+ if (text != null && String(text).trim()) n.setAttribute('data-i18n', navKey(text));+ return n;+ }function ensureCss() {if (document.querySelector('link[href="/getting-started.css"]')) return;var link = document.createElement('link');@@ -187,7 +206,7 @@glyph.setAttribute('aria-hidden', 'true');pillRing.appendChild(glyph);pill.appendChild(pillRing);- pill.appendChild(el('span', 'twg-pill-label', 'Getting started'));+ pill.appendChild(elT('span', 'twg-pill-label', 'Getting started'));pillCount = el('span', 'twg-pill-count');pill.appendChild(pillCount);pill.addEventListener('click', expand);@@ -220,7 +239,7 @@var head = el('div', 'twg-head');var headText = el('div', 'twg-head-text');- headText.appendChild(el('h2', 'twg-title', 'Getting started'));+ headText.appendChild(elT('h2', 'twg-title', 'Getting started'));panelSub = el('p', 'twg-sub');headText.appendChild(panelSub);head.appendChild(headText);@@ -268,10 +287,10 @@var body = el('div', 'twg-step-body');var title = el('div', 'twg-step-title');- title.appendChild(document.createTextNode(s.title));- if (!s.core) title.appendChild(el('span', 'twg-tag', 'Optional'));+ title.appendChild(elT('span', null, s.title));+ if (!s.core) title.appendChild(elT('span', 'twg-tag', 'Optional'));body.appendChild(title);- body.appendChild(el('div', 'twg-step-desc', s.desc));+ body.appendChild(elT('div', 'twg-step-desc', s.desc));row.appendChild(body);var arrow = el('span', 'twg-step-arrow');@@ -308,7 +327,7 @@}function sectionLabel(text) {- var li = el('li', 'twg-section-label', text);+ var li = elT('li', 'twg-section-label', text);li.setAttribute('role', 'presentation');return li;}@@ -363,7 +382,7 @@var body = el('div', 'twg-modal-body');body.appendChild(el('p', 'twg-modal-eyebrow', 'Welcome to three.ws'));- var title = el('h1', 'twg-modal-title', 'Give your AI a body — in about five minutes');+ var title = elT('h1', 'twg-modal-title', 'Give your AI a body — in about five minutes');title.id = 'twg-modal-title';body.appendChild(title);body.appendChild(el('p', 'twg-modal-lede',diff --git a/public/nav-data.js b/public/nav-data.jsindex 659fa7e02..7516ba8d0 100644--- a/public/nav-data.js+++ b/public/nav-data.js@@ -614,3 +614,18 @@ export const CHAT_SITE_LINKS = [{ label: 'Features', href: '/features' },{ label: 'Docs', href: '/docs' },];++// Stable i18n key for a nav label. The SAME function runs in the offline+// harvester (scripts/i18n-nav-harvest.mjs) so the keys nav.js emits at runtime+// and the keys baked into the catalog always match. Pure FNV-1a hash of the+// English string: identical text → identical key (auto-dedup), distinct text →+// distinct key (no collisions). Prefixed `nav.` so it groups in the catalog.+export function navKey(text) {+ const s = String(text == null ? '' : text);+ let h = 0x811c9dc5;+ for (let i = 0; i < s.length; i++) {+ h ^= s.charCodeAt(i);+ h = Math.imul(h, 0x01000193);+ }+ return 'nav.' + (h >>> 0).toString(36);+}diff --git a/public/nav.html b/public/nav.htmlindex ce9378823..aaf5666a8 100644--- a/public/nav.html+++ b/public/nav.html@@ -30,7 +30,7 @@<circle cx="7.5" cy="7.5" r="5" /><line x1="11.5" y1="11.5" x2="16" y2="16" /></svg>- <span class="nav-search-label">Search</span>+ <span class="nav-search-label" data-i18n="nav.1j0itop">Search</span><kbd class="nav-search-hint" aria-hidden="true">⌘K</kbd></button><button@@ -42,7 +42,7 @@title="Walk with me"><span class="nav-walk-ico" aria-hidden="true">🚶</span- ><span class="nav-walk-label">Walk</span>+ ><span class="nav-walk-label" data-i18n="nav.9nlxdc">Walk</span></button><buttontype="button"@@ -111,9 +111,9 @@</svg><span class="nav-notif-badge" hidden aria-live="polite"></span></button>- <a href="/dashboard" id="home-nav-dashboard-li" data-auth="in" hidden>Dashboard</a>- <a href="/login" id="home-nav-cta" data-auth="out">Sign in</a>- <a class="console" href="/dashboard" id="home-nav-user" data-auth-name>Console →</a>+ <a href="/dashboard" id="home-nav-dashboard-li" data-auth="in" hidden data-i18n="nav.4zftyz">Dashboard</a>+ <a href="/login" id="home-nav-cta" data-auth="out" data-i18n="nav.w9nig3">Sign in</a>+ <a class="console" href="/dashboard" id="home-nav-user" data-auth-name data-i18n="nav.15pjwv8">Console →</a></div><button class="nav-toggle" aria-label="Menu" aria-expanded="false" id="nav-toggle"><svgdiff --git a/public/nav.js b/public/nav.jsindex 9b47d4361..d36a74454 100644--- a/public/nav.js+++ b/public/nav.js@@ -214,6 +214,14 @@ function boot() {.then(([html, navData]) => {navContainer.innerHTML = html;renderMenus(navContainer, navData);+ // Translate the freshly-injected nav immediately for the active locale+ // (the i18n runtime's observer also catches it, this just avoids a frame+ // of English on first paint). Safe no-op if i18n hasn't loaded yet.+ try {+ window.threewsI18n?.apply?.(navContainer);+ } catch {+ /* i18n not present on this page — nav stays English */+ }initNav(navContainer);loadNotificationsInbox();loadHolderBadge();@@ -246,6 +254,16 @@ function escHtml(s) {.replace(/"/g, '"');}+// i18n: scripts/i18n-nav-harvest.mjs baked every nav string into the catalog+// under navKey(text). Emitting the same key here lets the runtime (src/i18n.js,+// via its injected-content MutationObserver) swap each label for the active+// locale, and re-swap on a language switch. `NK` is replaced with nav-data.js's+// real navKey in renderMenus; the placeholder only guards against an early call.+let NK = (t) => 'nav.' + String(t);+function i18nAttr(text) {+ return text && String(text).trim() ? ` data-i18n="${escHtml(NK(text))}"` : '';+}+function attrString(attrs) {if (!attrs) return '';return Object.keys(attrs)@@ -255,11 +273,13 @@ function attrString(attrs) {function renderMenuItem(item) {const tone = item.badgeTone === 'live' ? ' nav-pill-live' : '';- const badge = item.badge ? ` <span class="nav-pill-sm${tone}">${escHtml(item.badge)}</span>` : '';+ const badge = item.badge+ ? ` <span class="nav-pill-sm${tone}"${i18nAttr(item.badge)}>${escHtml(item.badge)}</span>`+ : '';return (`<a class="nav-mi" href="${escHtml(item.href)}" role="menuitem"${attrString(item.attrs)}>` +- `<span class="nav-mi-t">${escHtml(item.title)}${badge}</span>` +- `<span class="nav-mi-d">${escHtml(item.desc)}</span></a>`+ `<span class="nav-mi-t"><span${i18nAttr(item.title)}>${escHtml(item.title)}</span>${badge}</span>` ++ `<span class="nav-mi-d"${i18nAttr(item.desc)}>${escHtml(item.desc)}</span></a>`);}@@ -275,13 +295,15 @@ function renderGroup(group) {} else if (group.layout === 'wide') {popClass += ' wide';}- const note = group.note ? `<div class="nav-pop-note">${escHtml(group.note)}</div>` : '';+ const note = group.note+ ? `<div class="nav-pop-note"${i18nAttr(group.note)}>${escHtml(group.note)}</div>`+ : '';const body = group.columns? group.columns.map((col) =>`<div class="nav-col" role="group" aria-label="${escHtml(col.label)}">` +- `<div class="nav-col-h">${escHtml(col.label)}</div>` ++ `<div class="nav-col-h"${i18nAttr(col.label)}>${escHtml(col.label)}</div>` +col.items.map(renderMenuItem).join('') +`</div>`,)@@ -290,7 +312,7 @@ function renderGroup(group) {return (`<div class="nav-grp">` +`<button type="button" class="nav-trigger" aria-haspopup="true" aria-expanded="false">` +- `${escHtml(group.label)}${badge}<span class="nav-caret" aria-hidden="true">▾</span></button>` ++ `<span${i18nAttr(group.label)}>${escHtml(group.label)}</span>${badge}<span class="nav-caret" aria-hidden="true">▾</span></button>` +`<div class="${popClass}" role="menu" aria-label="${escHtml(group.label)}">${note}${body}</div>` +`</div>`);@@ -301,15 +323,17 @@ function renderTopLink(link) {return (`<a class="nav-hot" href="${escHtml(link.href)}">` +`<span class="nav-hot-dot" aria-hidden="true"></span>` +- `<span class="nav-hot-label">${escHtml(link.label)}</span></a>`+ `<span class="nav-hot-label"${i18nAttr(link.label)}>${escHtml(link.label)}</span></a>`);}- const badge = link.badge ? ` <span class="nav-pill-sm">${escHtml(link.badge)}</span>` : '';- return `<a href="${escHtml(link.href)}">${escHtml(link.label)}${badge}</a>`;+ const badge = link.badge+ ? ` <span class="nav-pill-sm"${i18nAttr(link.badge)}>${escHtml(link.badge)}</span>`+ : '';+ return `<a href="${escHtml(link.href)}"><span${i18nAttr(link.label)}>${escHtml(link.label)}</span>${badge}</a>`;}function renderDrawerLink(item) {- return `<a href="${escHtml(item.href)}"${attrString(item.attrs)}>${escHtml(item.title)}</a>`;+ return `<a href="${escHtml(item.href)}"${attrString(item.attrs)}${i18nAttr(item.title)}>${escHtml(item.title)}</a>`;}function renderDrawer(navData) {@@ -321,41 +345,42 @@ function renderDrawer(navData) {html +=`<button type="button" class="dr-walk" id="home-nav-drawer-walk" aria-pressed="false">` +`<span class="nav-walk-ico" aria-hidden="true">🚶</span>` +- `<span class="dr-walk-label">Walk with me</span>` +- `<span class="dr-walk-state" aria-hidden="true">Off</span></button>`;+ `<span class="dr-walk-label"${i18nAttr('Walk with me')}>Walk with me</span>` ++ `<span class="dr-walk-state" aria-hidden="true"${i18nAttr('Off')}>Off</span></button>`;// Highlighted top-level links lead the drawer as featured rows — burying// the one link the nav spotlights under "More" defeats the spotlight.navData.NAV_LINKS.filter((l) => l.highlight).forEach((link) => {html +=`<a class="dr-hot" href="${escHtml(link.href)}">` +`<span class="nav-hot-dot" aria-hidden="true"></span>` +- `<span>${escHtml(link.label)}</span>` ++ `<span${i18nAttr(link.label)}>${escHtml(link.label)}</span>` +`<span class="dr-hot-arrow" aria-hidden="true">→</span></a>`;});navData.NAV_GROUPS.forEach((group) => {if (group.columns) {group.columns.forEach((col) => {- html += `<div class="dr-h">${escHtml(group.label)} · ${escHtml(col.label)}</div>`;+ html += `<div class="dr-h"><span${i18nAttr(group.label)}>${escHtml(group.label)}</span> · <span${i18nAttr(col.label)}>${escHtml(col.label)}</span></div>`;html += col.items.map(renderDrawerLink).join('');});} else {- html += `<div class="dr-h">${escHtml(group.label)}</div>`;+ html += `<div class="dr-h"${i18nAttr(group.label)}>${escHtml(group.label)}</div>`;html += (group.items || []).map(renderDrawerLink).join('');}});- html += `<div class="dr-h">Legal</div>`;+ html += `<div class="dr-h"${i18nAttr('Legal')}>Legal</div>`;html += navData.DRAWER_LEGAL.map(renderDrawerLink).join('');- html += `<div class="dr-h">More</div>`;+ html += `<div class="dr-h"${i18nAttr('More')}>More</div>`;html += navData.NAV_LINKS.filter((l) => !l.highlight).map(renderTopLink).join('');- html += `<a href="/dashboard" id="home-nav-drawer-dashboard" data-auth="in" hidden>Dashboard</a>`;- html += `<a href="/guardian" id="home-nav-drawer-guardian" data-auth="in" hidden>Guardian console</a>`;+ html += `<a href="/dashboard" id="home-nav-drawer-dashboard" data-auth="in" hidden${i18nAttr('Dashboard')}>Dashboard</a>`;+ html += `<a href="/guardian" id="home-nav-drawer-guardian" data-auth="in" hidden${i18nAttr('Guardian console')}>Guardian console</a>`;html += `<div class="sep"></div>`;- html += `<a href="/login" id="home-nav-drawer-cta" data-auth="out">Sign in</a>`;- html += `<a class="btn primary btn--primary" href="/dashboard">Console →</a>`;+ html += `<a href="/login" id="home-nav-drawer-cta" data-auth="out"${i18nAttr('Sign in')}>Sign in</a>`;+ html += `<a class="btn primary btn--primary" href="/dashboard"${i18nAttr('Console →')}>Console →</a>`;return html;}function renderMenus(root, navData) {+ if (typeof navData.navKey === 'function') NK = navData.navKey;const main = root.querySelector('.nav-main');if (main) {main.innerHTML =diff --git a/scripts/i18n-nav-harvest.mjs b/scripts/i18n-nav-harvest.mjsnew file mode 100644index 000000000..e07e4f3f6--- /dev/null+++ b/scripts/i18n-nav-harvest.mjs@@ -0,0 +1,126 @@+#!/usr/bin/env node+// i18n-nav-harvest — bake the runtime-built shell strings into the source+// catalog (public/locales/en.json).+//+// The global nav (public/nav.js from public/nav-data.js) and the getting-started+// widget (public/getting-started.js) render their text with JavaScript, so the+// HTML-scanning i18n:extract never sees them. nav.js/getting-started.js emit+// `data-i18n="<navKey(text)>"` at render time; this script computes the SAME+// keys (via nav-data.js's navKey) for every English string they render and+// writes them into en.json, so i18n:translate then localizes them and the+// runtime swaps them in the injected DOM.+//+// Run before i18n:extract + i18n:translate:+// node scripts/i18n-nav-harvest.mjs+//+// Keep the EXTRA_STRINGS lists in sync with the inline literals in nav.js and+// getting-started.js (the ones not sourced from nav-data.js).++import { readFileSync, writeFileSync } from 'node:fs';+import { resolve, dirname } from 'node:path';+import { fileURLToPath } from 'node:url';+import { pathToFileURL } from 'node:url';++const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const EN_PATH = resolve(ROOT, 'public/locales/en.json');++const { NAV_GROUPS, NAV_LINKS, DRAWER_LEGAL, CHAT_SITE_LINKS, navKey } = await import(+ pathToFileURL(resolve(ROOT, 'public/nav-data.js')).href+);++// Every user-visible string the nav data model carries.+function navDataStrings() {+ const out = [];+ const push = (s) => {+ if (typeof s === 'string' && s.trim()) out.push(s);+ };+ for (const g of NAV_GROUPS || []) {+ push(g.label);+ push(g.badge);+ push(g.note);+ for (const col of g.columns || []) {+ push(col.label);+ for (const it of col.items || []) {+ push(it.title);+ push(it.desc);+ push(it.badge);+ }+ }+ for (const it of g.items || []) {+ push(it.title);+ push(it.desc);+ push(it.badge);+ }+ }+ for (const l of NAV_LINKS || []) {+ push(l.label);+ push(l.badge);+ }+ for (const l of CHAT_SITE_LINKS || []) push(l.label);+ for (const l of DRAWER_LEGAL || []) push(l.title);+ return out;+}++// Inline literals rendered by nav.js (renderDrawer + shell) that are not in+// nav-data.js. Mirror of the strings nav.js wraps with data-i18n.+const NAV_JS_STRINGS = [+ 'Walk with me',+ 'Off',+ 'On',+ 'Legal',+ 'More',+ 'Sign in',+ 'Console →',+ 'Guardian console',+ 'Dashboard',+];++// Inline literals rendered by getting-started.js.+const GETTING_STARTED_STRINGS = [+ 'Getting started',+ 'Give your AI a body — in about five minutes',+ 'Create your first avatar',+ 'Selfie, text prompt, or upload — your 3D agent in a couple of minutes.',+ 'Give it a brain',+ 'Add a name, personality, and voice so it can talk back.',+ 'Embed it anywhere',+ 'Drop one line of HTML onto any site — it loads and animates itself.',+ 'Own it on-chain',+ 'Register your agent on-chain so its identity is verifiable.',+ 'Monetize it',+ 'Charge for skills and collect creator fees from the agent economy.',+ 'Free · the core path',+ 'Optional add-ons',+ 'Optional',+];++function flatten(obj, prefix = '', out = {}) {+ for (const [k, v] of Object.entries(obj || {})) {+ const key = prefix ? `${prefix}.${k}` : k;+ if (v && typeof v === 'object' && !Array.isArray(v)) flatten(v, key, out);+ else out[key] = v;+ }+ return out;+}+function setDeep(obj, dotted, value) {+ const parts = dotted.split('.');+ let node = obj;+ for (let i = 0; i < parts.length - 1; i++) {+ if (!node[parts[i]] || typeof node[parts[i]] !== 'object') node[parts[i]] = {};+ node = node[parts[i]];+ }+ node[parts[parts.length - 1]] = value;+}++const en = JSON.parse(readFileSync(EN_PATH, 'utf8'));+const existing = flatten(en);+const all = [...new Set([...navDataStrings(), ...NAV_JS_STRINGS, ...GETTING_STARTED_STRINGS])];++let added = 0;+for (const text of all) {+ const key = navKey(text);+ if (existing[key] === undefined) added++;+ setDeep(en, key, text);+}+writeFileSync(EN_PATH, JSON.stringify(en, null, '\t') + '\n');+console.log(`i18n-nav-harvest: ${all.length} shell string(s) → ${added} new key(s) in en.json`);diff --git a/src/i18n.js b/src/i18n.jsindex d38320298..baba3105e 100644--- a/src/i18n.js+++ b/src/i18n.js@@ -314,12 +314,49 @@ async function injectHreflang() {document.head.appendChild(frag);}+// Re-translate DOM that is injected AFTER the initial pass — the global nav,+// the getting-started widget, and any other runtime-built shell are fetched and+// rendered asynchronously, so they miss the initI18n applyCatalog(document).+// A MutationObserver translates each newly-added subtree that carries data-i18n+// annotations, batched on an animation frame so a burst of DOM writes costs one+// pass. setLocale still re-applies to the whole document on a language switch,+// so this only has to cover the first render of injected content.+function observeInjectedContent() {+ if (!hasDOM || typeof MutationObserver === 'undefined' || !document.body) return;+ const pending = new Set();+ let scheduled = false;+ const schedule = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (fn) => setTimeout(fn, 16);+ const flush = () => {+ scheduled = false;+ const roots = [...pending];+ pending.clear();+ for (const root of roots) applyCatalog(root, t);+ };+ const SEL = '[data-i18n],[data-i18n-html],[data-i18n-attr]';+ const observer = new MutationObserver((mutations) => {+ for (const m of mutations) {+ for (const node of m.addedNodes) {+ if (node.nodeType !== 1) continue;+ if (node.matches?.(SEL) || node.querySelector?.(SEL)) pending.add(node);+ }+ }+ if (pending.size && !scheduled) {+ scheduled = true;+ schedule(flush);+ }+ });+ observer.observe(document.body, { childList: true, subtree: true });+}+// Auto-initialize on load so any page that ships this script is localized with// zero per-page wiring.if (hasDOM) {registerLangSwitcher();const boot = async () => {await initI18n();+ observeInjectedContent();+ // Catch content injected during init (before the observer was attached).+ applyCatalog(document, t);mountFloatingSwitcher();injectHreflang();};@@ -328,5 +365,8 @@ if (hasDOM) {} else {boot();}- window.threewsI18n = { t, setLocale, getLocale, initI18n };+ // `apply` lets a runtime-built component (nav.js, getting-started.js) request+ // an immediate translation of the subtree it just rendered, without waiting+ // for the observer's next frame.+ window.threewsI18n = { t, setLocale, getLocale, initI18n, apply: (root) => applyCatalog(root || document, t) };}