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
i18n: keep incomplete catalogs out of the language switcher
nirholas5fd9b4309e27
diff --git a/docs/i18n.md b/docs/i18n.mdindex 3f34444e4..aeaa33f06 100644--- a/docs/i18n.md+++ b/docs/i18n.md@@ -167,9 +167,18 @@ default), fetches `/locales/<code>.json` once, rewrites the annotated DOM, setsfall back to English, so partial locales degrade gracefully. `window.threewsI18n`exposes `{ t, setLocale, getLocale, initI18n }`.-The `<lang-switcher>` reads `public/locales/manifest.json` and only lists locales-with a committed catalog, so it never offers a language that would fall back to-English.+The `<lang-switcher>` reads `public/locales/manifest.json`, which lists only+locales whose catalog is **complete**, so it never offers a language that would+fall back to English. Presence of the file is not enough: `writeManifest()` counts+untranslated (empty) values via `untranslatedCount()` and holds back any catalog+that still has them, reporting what it skipped:++```+• manifest: 48 locale(s) listed, 1 held back until complete: as (3 untranslated keys)+```++So a locale that is mid-translation is simply absent from the switcher until the+run finishes, instead of shipping as a half-translated page.## Adding a languagediff --git a/scripts/i18n-translate.mjs b/scripts/i18n-translate.mjsindex 31c55d156..7b5d83f44 100644--- a/scripts/i18n-translate.mjs+++ b/scripts/i18n-translate.mjs@@ -37,6 +37,7 @@ import {setDeep,getDeep,missingKeys,+ untranslatedCount,mergeOrdered,buildMasker,lintLocale,@@ -549,10 +550,30 @@ function persist(code, existing, translatedFlat) {}// Refresh the runtime manifest the locale switcher reads. Only locales with a-// committed catalog are listed, so the switcher never offers a language that+// COMPLETE catalog are listed, so the switcher never offers a language that// would silently fall back to English.+//+// File existence is not enough. A run that dies partway (expired credentials, an+// exhausted provider) still writes the full key skeleton with empty-string values+// for everything it never reached, so the catalog looks finished by key count and+// then renders as a half-translated page, because the runtime falls back to English+// per key. Listing such a locale is exactly the failure this manifest exists to+// prevent, so an incomplete catalog is skipped and reported rather than shipped.function writeManifest() {- const ready = (code) => code === cfg.entryLocale || existsSync(localePath(code));+ const skipped = [];+ const ready = (code) => {+ if (code === cfg.entryLocale) return true;+ if (!existsSync(localePath(code))) return false;+ let empty = 0;+ try {+ empty = untranslatedCount(readJSON(localePath(code)));+ } catch {+ skipped.push(`${code} (unreadable)`);+ return false;+ }+ if (empty) skipped.push(`${code} (${empty} untranslated key${empty === 1 ? '' : 's'})`);+ return empty === 0;+ };const localesList = [cfg.entryLocale, ...cfg.outputLocales].filter(ready).map((code) => ({code,name: cfg.localeNames?.[code] || code,@@ -563,6 +584,11 @@ function writeManifest() {resolve(ROOT, cfg.output, 'manifest.json'),JSON.stringify(manifest, null, '\t') + '\n',);+ if (skipped.length) {+ console.log(+ `• manifest: ${localesList.length} locale(s) listed, ${skipped.length} held back until complete: ${skipped.join(', ')}`,+ );+ }}// --- repair mode: re-translate only lint-failing keys ----------------------diff --git a/scripts/lib/i18n-shared.mjs b/scripts/lib/i18n-shared.mjsindex c1eb05721..82d96c8f0 100644--- a/scripts/lib/i18n-shared.mjs+++ b/scripts/lib/i18n-shared.mjs@@ -68,6 +68,22 @@ export function missingKeys(source, target) {});}+// How many keys in a catalog are present but not actually translated.+//+// A translate run that dies partway (expired credentials, an exhausted provider)+// still writes the full key skeleton with empty-string values for everything it+// never reached, so the catalog looks finished by key count while rendering as a+// half-translated page. Callers use this to tell "complete" from "merely present"+// before shipping a locale. Same empty-string rule as missingKeys, so a catalog+// with count 0 is exactly one that a resumed run would find nothing to do for.+export function untranslatedCount(catalog) {+ let n = 0;+ for (const value of Object.values(flatten(catalog || {}))) {+ if (typeof value !== 'string' || value.trim() === '') n++;+ }+ return n;+}+// Keys present in target but no longer in source — stale translations to prune.export function staleKeys(source, target) {const src = flatten(source);diff --git a/tests/i18n.test.js b/tests/i18n.test.jsindex 54616cc0b..396b5ae96 100644--- a/tests/i18n.test.js+++ b/tests/i18n.test.js@@ -17,6 +17,7 @@ import {lintLocale,mergeOrdered,missingKeys,+ untranslatedCount,flatten,setDeep,getDeep,@@ -157,6 +158,20 @@ describe('merge + diff', () => {expect(missingKeys(source, target).sort()).toEqual(['b.c', 'b.d']);});+ // A run killed partway leaves the full key skeleton with empty values, so a+ // key-count check calls it finished while the page renders half-translated.+ // The manifest gate uses this to tell "complete" from "merely present".+ it('counts skeleton-only keys as untranslated so partial catalogs are detectable', () => {+ expect(untranslatedCount({ a: 'uno', b: { c: 'dos' } })).toBe(0);+ expect(untranslatedCount({ a: 'uno', b: { c: '', d: ' ' } })).toBe(2);+ expect(untranslatedCount({})).toBe(0);+ });++ it('agrees with missingKeys, so a complete catalog leaves a resumed run nothing to do', () => {+ const partial = { a: 'uno', b: { c: '', d: '' } };+ expect(untranslatedCount(partial)).toBe(missingKeys(source, partial).length);+ });+it('keeps prior translations, applies fresh ones, and prunes stale keys', () => {const existing = { a: 'uno', b: { c: 'dos', d: 'tres' }, stale: 'x' };const fresh = {};