Files
ui/scripts/i18n-check.mjs
zeekayGitHubCursor Agentzhanzo-agentHanzo Devhanzo-platform[bot] <201622097+hanzo-platform[bot]@users.noreply.github.com>
fcedaff5b5 Localize built-in UI copy and the docs site (#266)
* @hanzo/ui 8.30.0: every word the package authors is the reader's language

- The consumer installs every peer of the train it pins
- @hanzo/ui 8.30.0: every word the package authors is the reader's language
- i18n: one English fallback, the footer's doors through t, and a typed header cell
- agents: the elements i18n touched draw with gui props, not style
- i18n: @hanzo/ui/product/pure still depends on nothing
- i18n: the framework's collections, records and media say their words in the reader's language
- i18n: one English fallback for the pure modules that build a sentence
- i18n: the builder workspace says its words in the reader's language
- i18n: settings, the catalogue shelf and the backdrop presets
- i18n: the masthead's tree is marked for translation and drawn through t
- i18n: the product layer says its words in the reader's language
- i18n: mockups and market widgets say their words in the reader's language
- i18n: the gui controls say their words in the reader's language
- picker: each choosable option wears the field's own ink
- consent: the bar's fit width is a gui prop
- i18n: onboarding, chat, the model picker, sign-in, consent and the corner speak the reader's language
- i18n: @hanzo/ui peer-depends on @hanzo/i18n

* feat(i18n): localize built-in UI copy and the docs site

English stays the default. A locale on Hanzo or LocaleProvider switches
built-in labels, chat copy, and dates, and Arabic sets dir=rtl. Missing
keys render in English. The docs site adds a language switcher, prefixed
routes, hreflang, and a localized sitemap.

Co-authored-by: z <[email protected]>

* docs: translate every page into the 16 target locales

Each English doc now has a locale file under data/i18n. Code fences,
previews, links, and product names stay as written. A missing file still
falls back to English.

Co-authored-by: z <[email protected]>

* Unfinished: these files still contain <<<<<<< / ======= / >>>>>>> conflict markers on origin/agent/i18n-locales-0366: pk…

Run: sess_498ba60a49b5870a63d042e97f565728

* No conflict markers remain. Now: pull origin agent/i18n-locales-0366 (merge), run pnpm install --frozen-lockfile (if it…

Run: sess_0a7901763139b331895f48f02df95b94

* CI on agent/i18n-locales-0366 head 362214f fails @hanzo/ui tests 1-8, ui browser/vite/webpack. Concrete errors: (a) pkg/…

Run: sess_79bff23928c2986ee61768a243fc6dfa

* fix(ui): Dial RING from look; drop duplicate useI18n in Masthead

Unblocks pkg/ui build on #266: RING lives in ./look (not ./ring); Masthead had a duplicate const { t } = useI18n() after the #254/#287 merge.

* fix(ui): rtl.test ALLOWED counts for Masthead/DiffViewer/SlideOver

Align ALLOWED physical-side budgets with current source after the i18n merge: Masthead 2, DiffViewer 5, SlideOver 1.

* fix(ui): RepoSelect test expects default note + troubleshoot

Co-authored-by: Hanzo Dev <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: z <[email protected]>
Co-authored-by: hanzo-agent <[email protected]>
Co-authored-by: Hanzo Dev <[email protected]>
Co-authored-by: hanzo-platform[bot] <201622097+hanzo-platform[bot]@users.noreply.github.com>
2026-11-05 04:11:17 -08:00

52 lines
1.7 KiB
JavaScript
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.
/**
* Every built-in string has a translation in every target locale.
*
* A missing key still renders in English at runtime (`translate` returns the
* source). This check is what stops a new string from shipping in English only
* without anyone noticing. Run it after adding a `tr('…')` / `t('…')` call:
*
* node scripts/i18n-check.mjs
*
* Exit 1 when a target catalog lacks a key from `pkg/ui/src/i18n/source.ts`,
* or a `{placeholder}` in the English is missing from a translation.
*/
import { readFileSync, readdirSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const source = readFileSync(join(root, 'pkg/ui/src/i18n/source.ts'), 'utf8')
const keys = [...source.matchAll(/^ {2}'(.*)',?$/gm)].map((m) => m[1])
const dir = join(root, 'pkg/ui/src/i18n/catalogs')
const files = readdirSync(dir).filter((name) => name.endsWith('.json'))
let failed = 0
if (keys.length === 0) {
console.error('no keys in source.ts')
process.exit(1)
}
for (const file of files) {
const catalog = JSON.parse(readFileSync(join(dir, file), 'utf8'))
for (const key of keys) {
const value = catalog[key]
if (typeof value !== 'string' || value.length === 0) {
console.error(`${file} missing ${JSON.stringify(key)}`)
failed++
continue
}
for (const token of key.match(/\{[a-zA-Z]+\}/g) ?? []) {
if (!value.includes(token)) {
console.error(`${file} dropped ${token} from ${JSON.stringify(key)}`)
failed++
}
}
}
}
if (failed) {
console.error(`${failed} problem(s). Runtime still falls back to English.`)
process.exit(1)
}
console.log(`${files.length} catalogs × ${keys.length} strings`)