Skip to content

i18n: address #1148 review follow-ups across validation, lazy locales, plural fallback, proxy, and test cache - #1310

Open
kruschdev wants to merge 2 commits into
pascalorg:mainfrom
kruschdev:fix/i18n-followups
Open

kruschdev wants to merge 2 commits into
pascalorg:mainfrom
kruschdev:fix/i18n-followups

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 23, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #1155

I addressed all seven deferred follow-up items from the #1148 i18n review:

  • Placeholder validation depth and stricter tag check (scripts/i18n.ts, scripts/i18n.test.ts):
    • Expanded tag scanning to treat any < followed by a letter, !, or / as a tag (catching <img/src=x onerror=...>, <svg/onload=...>, <!-- -->, and unclosed tags), plus Lingui numbered tags (<0>, </0>, <0/>), while ignoring spaced math comparisons like Width < 5 m.
    • Added stack-based tag nesting validation (tagNestingErrors) to catch broken nesting (<0><1>...</0></1>, </0>...<0>, mismatched or unclosed tags) and renumbered tags (<0> changed to <1>).
    • Added ICU select branch validation (selects) to catch missing or removed branches and missing other branches in both select and plural/selectordinal selectors.
  • Per-locale entry points (packages/editor/src/i18n/locales.ts, locales/*/index.ts, packages/editor/package.json, apps/editor/app/layout.tsx):
    • Added individual per-locale entry points (@pascal-app/editor/locales/{en,es,fr,ja,zh-CN}) and replaced top-level static imports of all five catalogs in locales.ts with dynamic per-locale loading (loadBundledLocale, resolveBundledLocale, registerBundledCatalog).
    • Updated apps/editor/app/layout.tsx and client-bootstrap.tsx to load only the active locale on the server and hand that single catalog to client hydration (avoiding both bundling all five locales up front and hydration mismatches).
  • Plural rules for fallback messages (packages/core/src/i18n/registry.ts, i18n.test.tsx):
    • Updated PascalI18n to resolve each message against a per-fallback-locale Lingui runtime so a pt message used under pt-PT evaluates with pt plural rules (0 -> one) while a pt-PT override uses pt-PT plural rules (0 -> other).
  • In-app ?lang= navigation (apps/editor/app/client-bootstrap.tsx, apps/editor/lib/ui-locale.ts):
    • Added a <Suspense>-wrapped LocaleQuerySync hook using useSearchParams() and resolveClientLangNavigation so client-side navigation to ?lang=... switches the active language and dynamically loads its catalog without a full reload, while preserving the SSR default locale on back/internal navigation.
  • Full proxy() tests (apps/editor/proxy.test.ts):
    • Added end-to-end tests invoking proxy(new NextRequest(...)) covering auth gating (307/401 without locale pass-through), forwarded canonical x-pascal-locale headers on allowed requests, overwriting client-spoofed x-pascal-locale headers, and query-string matcher behavior.
  • Cached Turbo task for i18n script tests (package.json, apps/editor/package.json, turbo.json):
    • Moved scripts/i18n*.test.ts into a cached root Turbo task (//#test:i18n-scripts) with explicit inputs and moved apps/editor/proxy.test.ts into editor#test, reducing warm reruns from ~66s to a ~72ms Turbo cache hit.

How to test

  1. Run bunx biome check on the modified files in scripts/, packages/core/, packages/editor/, and apps/editor/.
  2. Run bun test packages/core/src/i18n/ packages/editor/src/i18n/locales.test.ts apps/editor/proxy.test.ts (42 pass, 0 fail).
  3. Run bunx turbo run //#test:i18n-scripts twice (first run: 72 pass, 0 fail; second run: FULL TURBO cache hit in <100ms).
  4. Run bunx turbo run test --filter=editor (92 pass, 0 fail), bun run check:render-bundle, bun run i18n:check, and bunx turbo run check-types (15/15 packages).

Screenshots / screen recording

N/A (i18n validation, per-locale loading, plural fallback, proxy testing, and Turbo test caching).

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Touches core i18n resolution, client hydration/locale switching, and middleware locale headers—user-visible language behavior with moderate complexity but solid test coverage.

Overview
Addresses i18n review follow-ups by lazy-loading bundled locale catalogs (per-locale entry points and loadBundledLocale / registerBundledCatalog) instead of registering all five packs at startup. The editor SSR loads the active catalog and passes it through ClientBootstrap, with createLocaleApplier and LocaleQuerySync so ?lang= changes apply after the chunk loads without a full reload.

PascalI18n now picks the fallback locale’s Lingui runtime per message so ICU plurals use the catalog that supplied the string (e.g. pt vs pt-PT for count: 0).

The i18n check pipeline is tighter: richer tag detection and nesting checks, ICU select / plural other branch rules, plus tests. proxy() gains end-to-end locale-header tests; root //#test:i18n-scripts Turbo task caches script tests separately from apps/editor tests.

Reviewed by Cursor Bugbot for commit ef2da6b. Bugbot is set up for automated code reviews on this repo. Configure here.

…y locales, plural fallback, proxy, and test cache

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c45c747. Configure here.

Comment thread apps/editor/app/client-bootstrap.tsx Resolved

This branch has not been deployed

No deployments
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.

[Maintainer] i18n follow-ups from the #1148 review

1 participant