Skip to content

Optimize i18n bundle with lazy-loaded locale files#167

Merged
koala73 merged 3 commits into
mainfrom
claude/resolve-pr-conflict-yLgXf
Feb 20, 2026
Merged

Optimize i18n bundle with lazy-loaded locale files#167
koala73 merged 3 commits into
mainfrom
claude/resolve-pr-conflict-yLgXf

Conversation

@koala73

@koala73 koala73 commented Feb 20, 2026

Copy link
Copy Markdown
Owner

Summary

Refactors the i18n service to lazy-load locale files instead of bundling all translations upfront. English is eagerly imported as the fallback language, while all other locales are dynamically imported only when needed. Updates Vite configuration to handle locale chunk naming and service worker caching.

Type of change

  • Refactor / code cleanup
  • CI / Build / Infrastructure

Affected areas

  • Config / Settings
  • Other: Internationalization (i18n) and build optimization

Details

Changes to src/services/i18n.ts

  • Eagerly imports English translation (en.json) as the fallback language
  • Replaces the static LOCALE_LOADERS object with import.meta.glob() for dynamic locale loading
  • Updates ensureLanguageLoaded() to handle both the eagerly-loaded English and lazy-loaded locales
  • Adds fallback logic to use English if a requested locale file fails to load
  • Simplifies initI18n() to use the pre-imported English translation

Changes to vite.config.ts

  • Adds **/locale-*.js to service worker globIgnores to prevent precaching of lazy-loaded locale chunks
  • Adds a new service worker cache strategy for locale files (CacheFirst with 30-day expiration)
  • Implements custom chunk naming in the build config to prefix lazy-loaded locale files with locale- (excluding en.json which stays in the main bundle)

Benefits

  • Reduced initial bundle size: Only English is bundled by default; other locales load on-demand
  • Improved code splitting: Each locale becomes a separate chunk that can be cached independently
  • Better service worker handling: Locale chunks are excluded from precache and use appropriate caching strategies

Checklist

  • TypeScript compiles without errors
  • No API keys or secrets committed

https://claude.ai/code/session_01Hd1kUsbZaAw5vzhBWS9Mkx

Replace the static LOCALE_LOADERS map (14 explicit dynamic imports) with
import.meta.glob for lazy loading. English is now statically imported as
the always-needed fallback; all other 13 locales are loaded on demand.

- Statically import en.json so it's bundled eagerly (no extra fetch)
- Use import.meta.glob with negative pattern to lazy-load non-English
  locales only when the user actually switches language
- Add manualChunks rule to prefix lazy locale chunks with `locale-`
- Exclude locale-*.js from service worker precache via globIgnores
- Add CacheFirst runtime caching for locale files when loaded on demand

SW precache reduced from 43 entries (5587 KiB) to 29 entries (4840 KiB),
saving ~747 KiB from the initial download.

https://claude.ai/code/session_01TfRgC5GWsv51swxRSGxxeJ
Resolve conflict in vite.config.ts workbox config by combining both
branches: keep main's navigateFallback: null fix (prevents stale HTML
precache) while preserving the PR's locale-*.js glob ignore and
runtime cache strategy for lazy-loaded locale chunks.

https://claude.ai/code/session_01Hd1kUsbZaAw5vzhBWS9Mkx
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel

vercel Bot commented Feb 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Feb 20, 2026 4:34am
worldmonitor-finance Ready Ready Preview, Comment Feb 20, 2026 4:34am
worldmonitor-startup Ready Ready Preview, Comment Feb 20, 2026 4:34am

Request Review

@koala73
koala73 merged commit d417520 into main Feb 20, 2026
4 checks passed
@koala73
koala73 deleted the claude/resolve-pr-conflict-yLgXf branch February 20, 2026 04:34
facusturla pushed a commit to facusturla/worldmonitor that referenced this pull request Feb 27, 2026
## Summary

Refactors the i18n service to lazy-load locale files instead of bundling
all translations upfront. English is eagerly imported as the fallback
language, while all other locales are dynamically imported only when
needed. Updates Vite configuration to handle locale chunk naming and
service worker caching.

## Type of change

- [x] Refactor / code cleanup
- [x] CI / Build / Infrastructure

## Affected areas

- [x] Config / Settings
- [x] Other: Internationalization (i18n) and build optimization

## Details

### Changes to `src/services/i18n.ts`
- Eagerly imports English translation (`en.json`) as the fallback
language
- Replaces the static `LOCALE_LOADERS` object with `import.meta.glob()`
for dynamic locale loading
- Updates `ensureLanguageLoaded()` to handle both the eagerly-loaded
English and lazy-loaded locales
- Adds fallback logic to use English if a requested locale file fails to
load
- Simplifies `initI18n()` to use the pre-imported English translation

### Changes to `vite.config.ts`
- Adds `**/locale-*.js` to service worker `globIgnores` to prevent
precaching of lazy-loaded locale chunks
- Adds a new service worker cache strategy for locale files
(`CacheFirst` with 30-day expiration)
- Implements custom chunk naming in the build config to prefix
lazy-loaded locale files with `locale-` (excluding `en.json` which stays
in the main bundle)

## Benefits

- **Reduced initial bundle size**: Only English is bundled by default;
other locales load on-demand
- **Improved code splitting**: Each locale becomes a separate chunk that
can be cached independently
- **Better service worker handling**: Locale chunks are excluded from
precache and use appropriate caching strategies

## Checklist

- [x] TypeScript compiles without errors
- [x] No API keys or secrets committed

https://claude.ai/code/session_01Hd1kUsbZaAw5vzhBWS9Mkx
koala73 added a commit that referenced this pull request Apr 11, 2026
…riter

Resolves all 5 critical findings from the multi-agent code review of PR #2940.
End-to-end smoke test passes for all 8 regions with confidence=1.0.

P1 #166: health-seed-meta-not-in-keys-loops
  - Add regionalSnapshots to STANDALONE_KEYS in api/health.js
  - Without this, the SEED_META entry was dead wiring and the 12h staleness
    budget was unobservable. Same failure mode as the 'empty data ok keys
    bootstrap blind spot' the team has hit before.

P1 #167: oref-trigger-key-not-in-freshness-registry
  - Add relay:oref:history:v1 to FRESHNESS_REGISTRY (the canonical OREF key
    written by ais-relay, not the wrong intelligence:oref-alerts:v1 that the
    code was originally reading).
  - Update trigger-evaluator to read activeAlertCount/historyCount24h from
    the actual relay:oref:history:v1 payload shape.
  - oref_cluster trigger now fires when activeAlertCount > 10 (verified
    end-to-end against mock data).

P1 #168: zombie-freshness-registry-keys
  - Remove 4 freshness registry entries that no compute module reads:
    supply_chain:shipping_stress, energy:chokepoint-flows,
    intelligence:advisories-bootstrap, market:commodities-bootstrap.
  - These were dragging snapshot_confidence below 1.0 and wasting Redis
    pipeline reads. Add a header comment forbidding speculative entries.

P1 #169: diff-field-leaks-into-persisted-snapshot
  - Change computeSnapshot to return { snapshot, diff } separately so the
    diff is consumed locally for inferTriggerReason and never serialized
    into the persisted snapshot. The diff field was not part of the
    RegionalSnapshot type and would have broken Phase 1 proto codegen.
  - Update main() to destructure { snapshot } before persistSnapshot.

P1 #170: jsdoc-types-not-enforced-jsconfig-missing
  - Add scripts/seed-regional-snapshots.mjs and scripts/regional-snapshot/**
    to scripts/jsconfig.json's include array so tsc --checkJs validates the
    JSDoc @type annotations.
  - Add // @ts-check directive to all 14 .mjs files in the regional-snapshot
    pipeline.
  - Fix 4 type-safety bugs surfaced by enabling type-checking:
      actor-scoring: explicit ActorState[] type on local actors array; cast
        leverage_domains to ActorLeverageDomain[]; typed ActorRole return on
        inferRole.
      evidence-collector: explicit EvidenceItem[] type on local out array.
      scenario-builder: typed HORIZONS as ScenarioHorizon[] and LANE_NAMES
        as ScenarioName[].
      transmission-templates: cast tpl.affectedRegions to RegionId[] when
        building TransmissionPath objects.
  - Pre-existing seed-forecasts.mjs and _r2-storage.mjs errors (46 total)
    are not part of this PR's scope and remain untouched.

Verification
  - npx tsc --noEmit -p scripts/jsconfig.json: 0 errors in regional-snapshot files
  - npm run typecheck:all: clean
  - npm run test:data: 3946/3946 pass
  - tests/regional-snapshot.test.mjs: 50/50 pass
  - End-to-end smoke test: all 8 regions compute clean with confidence=1.0
  - Verified: oref_cluster trigger fires when activeAlertCount > 10
  - Verified: persisted snapshot has no diff field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants