Commit Graph

5 Commits

Author SHA1 Message Date
Evan
099cdcdec8 fix(i18n): accept script-subtag locales, annotate test helper return type
The language-code regex only allowed a 2-letter region subtag, so
locales Superset actually ships with a script subtag (e.g. sr_Latn)
were rejected by /language_pack/<lang>/<version>/script.js with a 400
and silently fell back to English. Widen the shared LANGUAGE_CODE_RE
to accept both region and script subtags, and add a regression test.

Also gives the test helper an explicit dict[str, Any] return type so
the inferred `context` locals in test_bootstrap_auth.py are annotated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 09:05:14 -07:00
Evan
95d1f6b699 fix(i18n): annotate remaining language-pack locals
Add explicit type hints to the local variables left un-annotated in the
language-pack view and its tests, matching the typed style already used
for their neighbors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 17:18:28 -07:00
Evan
ee8eace7ba fix(i18n): annotate test locals, short-circuit missing language packs
Address CodeAnt nits (explicit type hints on new test locals) and a
short-circuit on language_pack_script so a nonexistent locale skips
the redundant pack-file read and error log once the version lookup
already returns None.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 05:03:12 -07:00
Evan Rusackas
399944ec41 test(i18n): fix pre-commit failures and pin language pack loading semantics
Fixes the two CI failures (generator fixture annotated Iterator[None],
stray unused import in the test package init) and adds tests encoding
the delivery contract:

- English configures the translator bare and never loads a pack (zero
  payload, no fetch).
- Non-English configures synchronously from the window global set by
  the versioned classic script tag, with no fetch and no English flash.
- An operator-supplied bootstrap pack takes precedence over the window
  global.
- The fallback fetch requests only the selected locale and resolves
  before initPreamble() returns, so even that path renders translated.
- The endpoint resolves exactly the locale in the URL and nothing else.
- Static guard: spa.html's pack script tag precedes the entry bundle
  and carries no async/defer, preserving execution order.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 14:23:39 -07:00
Evan Rusackas
4fe238da42 feat(i18n): serve language packs as versioned, immutable-cacheable scripts
Follow-up to #39357, which inlined the Jed language pack into the
bootstrap HTML to fix the code-split translation race (#35330). That
made non-English full-page loads carry ~67KB (gzipped) of pack on every
request since HTML is uncacheable.

This keeps the synchronous-configuration guarantee but moves the pack
to a content-addressed script: spa.html emits
<script src="/language_pack/<lang>/<version>/script.js"> before the
entry bundle, where <version> is a short content hash of the pack file.
The endpoint serves window.__SUPERSET_LANGUAGE_PACK__ = {...} with
Cache-Control: public, max-age=31536000, immutable, so browsers fetch
the pack once per translation change instead of once per page load, and
cache-bust automatically on upgrade (fixing the stale-pack window the
unversioned /language_pack/<lang>/ fetch had under the 1-year
SEND_FILE_MAX_AGE_DEFAULT).

Details:
- English emits no tag and pays nothing.
- A stale version in a cached HTML page still gets current content,
  served no-cache so it can't pin under the wrong address.
- Packs provided via COMMON_BOOTSTRAP_OVERRIDES_FUNC still ride the
  bootstrap payload and suppress the script tag (spa.html stashes them
  on window instead), preserving the historical workaround.
- The endpoint is deliberately unauthenticated: catalogs are static
  public repo content with no user data, and must load for anonymous
  principals (login page, embedded).
- preamble.ts fallback chain unchanged: bootstrap pack, window global,
  then async fetch if the script failed to load.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 14:23:39 -07:00