i18n: audience-scoped catalogs + branded scaffold title (#248, #249) - #251
Merged
Conversation
Fixes #248: every module's locale catalog shipped in every Inertia payload — an anonymous visitor on a public content page downloaded ~8 KB of admin form labels (permissions, settings, branding, ...) per full page load, growing linearly with installed modules. - ModuleMeta gains i18n_audience ("public" default, "admin" opt-in). - I18nRegistry.add_source() takes the audience; load() precomputes a public snapshot alongside the full one, so the hot path stays a dict lookup either way. messages_snapshot(locale, include_admin=False) returns the anonymous variant; server-side Translator lookups always see every namespace. - build_i18n_block() picks the snapshot by auth state and tracks the served audience in the session next to the locale: a login (or logout) mid-session re-ships the messages even on an Inertia partial, so a freshly-authenticated client is never left holding the anonymous catalog. - The framework's admin modules (settings, permissions, dashboard, file_storage, audit_log, feature_flags, background_tasks, branding) declare i18n_audience="admin". auth/users/keycloak stay public — anonymous visitors see their login flows. Fixes #249: the create-host scaffold hardcoded <title>SimpleModule</title> even though branding_head() — added for exactly this in #175 — was already registered as a Jinja global. The scaffold now renders the branded title and theme-color the same way the in-repo dev host does. Claude-Session: https://claude.ai/code/session_01LHXd7LmearTryWpnf4ksKD
Deploying simple-module-python with
|
| Latest commit: |
4a427b4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2c0a939f.simple-module-python.pages.dev |
| Branch Preview URL: | https://fix-i18n-audience-and-scaffo.simple-module-python.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #248 and #249 — the two framework-level findings from the globalcanopyatlas perf pass (the module-level ones moved to smpy_modules and are fixed in antosubash/smpy_modules#18).
#248 — stop shipping admin catalogs to anonymous visitors
Measured on a public content page: 9.4 KB of i18n in every full-page payload, ~85% of it admin-only strings (permissions 2.6 KB, settings 2 KB, branding 1.3 KB, file_storage 1.3 KB, dashboard 0.7 KB) an anonymous visitor can never render — and it grows with every installed module.
Design (option 1 from the issue — module-declared audience):
ModuleMeta.i18n_audience:"public"(default — ships to everyone, fully backward compatible) or"admin"(ships only to authenticated users).I18nRegistry:add_source(..., audience=...);load()precomputes a public snapshot next to the full one, so the request hot path stays a precomputed-dict lookup either way.messages_snapshot(locale, include_admin=False)is the anonymous variant. Server-sideTranslatorlookups are unaffected — every namespace stays visible.build_i18n_blockpicks the snapshot byis_authenticatedand tracks the served audience in the session alongside the locale. The subtle case is covered: login mid-session re-ships messages even on an Inertia partial (which normally sendsmessages: None), so a freshly-authenticated client isn't stuck with the anonymous catalog until a hard reload. Logout likewise."admin". auth/users/keycloak stay public — their flows render for anonymous users. Docs:docs/framework/i18n.md§ Audience.#249 — scaffold title
create-host'sindex.htmlstill hardcoded<title>SimpleModule</title>; thebranding_head()Jinja global (the #175 fix) existed but nothing scaffolded called it. The template now renders the branded title +theme-color, matching the in-repo dev host. Verified in a consuming host (iiasa/globalcanopyatlas#5).Verification
framework/core+framework/hostingi18n suites extended: public-snapshot exclusion, default-audience passthrough, anonymous vs authenticated payloads, the login-partial re-ship, and the unchanged-audience skip (40 i18n tests green).make test-py: 1,721 passed, 2 skipped.make test-js: 48 passed. ruff/format, biome,ty check framework/core framework/hosting, and the 300-line cap all clean.tyflagsframework/cli/tests/test_cli_package_update.py(typer._click.exceptionsimport, from feat: pluggable auth — AuthProvider contract + Keycloak OIDC module + bearer tokens #184) in my local env; untouched by this PR.https://claude.ai/code/session_01LHXd7LmearTryWpnf4ksKD