mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
Entry transfer measured with curl (compressed) against live hanzo.chat: 3,364,175 B before -> 2,171,335 B after (-1,192,840 B, -35.5%). - locales: only `en` stays bundled (it is the fallback AND the source of translation-key types). The other 40 languages load through an i18next lazy backend over import.meta.glob — each translation.json becomes its own on-demand chunk (was: one 572KB-gzip entry-blocking 'locales' chunk). The vite manualChunks 'locales' rule is deleted: welding the lazy files to the eagerly-imported `en` module would drag them all straight back into the entry graph. - heic-to (667KB gzip WASM HEIF decoder) is imported lazily from heicConverter.ts; the cost moves to the first .heic attach, where a decode is happening anyway. - jest: import.meta.glob is Vite syntax babel-jest cannot parse, so the glob lives alone in locales/localeLoaders.ts and jest maps that ONE module to an fs-backed twin with the identical shape — the REAL i18n module runs under tests, by any import specifier. Translation.spec now awaits changeLanguage (loading is async under the lazy backend) and passes against real fr/es bundles. Full client suite: 76 failed suites / 509 failed tests before AND after — zero regressions added. - /welcome hero: the terminal mock now says hanzo.chat (chat.hanzo.ai is a 301) and shows a chat/search session instead of hanzo.app's coding story. Co-authored-by: Hanzo Dev <[email protected]>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
/**
|
|
* Jest twin of `src/locales/localeLoaders.ts` (mapped in jest.config.cjs).
|
|
*
|
|
* The real module enumerates lazy locale loaders with `import.meta.glob`,
|
|
* which babel-jest cannot parse. This twin builds the SAME shape —
|
|
* `{ './<lng>/translation.json': () => Promise<{ default: bundle }> }` —
|
|
* from the filesystem, so i18n behavior under tests (including real French /
|
|
* Spanish lookups in Translation.spec) matches production.
|
|
*/
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
const localesDir = path.join(__dirname, '../src/locales');
|
|
|
|
export const localeLoaders: Record<string, () => Promise<{ default: Record<string, string> }>> =
|
|
Object.fromEntries(
|
|
fs
|
|
.readdirSync(localesDir, { withFileTypes: true })
|
|
.filter((entry) => entry.isDirectory())
|
|
.map((entry) => [
|
|
`./${entry.name}/translation.json`,
|
|
() =>
|
|
Promise.resolve({
|
|
default: JSON.parse(
|
|
fs.readFileSync(path.join(localesDir, entry.name, 'translation.json'), 'utf8'),
|
|
) as Record<string, string>,
|
|
}),
|
|
]),
|
|
);
|