From 97ceb1c368cb1a75af4e27ec61dbcee856bf2160 Mon Sep 17 00:00:00 2001 From: Anto Subash Date: Thu, 12 Nov 2026 17:09:29 +0100 Subject: [PATCH 1/5] fix(cli): generated module pages read their locale file (#918) Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4 --- CLAUDE.md | 4 +- .../cli/simple_module_cli/scaffolding.py | 9 ++- .../templates/docker/host-flat.Dockerfile | 5 +- .../templates/docker/host.Dockerfile | 5 +- .../simple_module_cli/templates/host/Makefile | 4 +- .../module/__PACKAGE__/pages/Browse.tsx.tpl | 36 +++++----- .../module/__PACKAGE__/pages/Create.tsx.tpl | 12 ++-- .../module/__PACKAGE__/pages/Edit.tsx.tpl | 12 ++-- .../__PACKAGE__/pages/Browse.tsx.tpl | 36 +++++----- .../__PACKAGE__/pages/Create.tsx.tpl | 12 ++-- .../__PACKAGE__/pages/Edit.tsx.tpl | 12 ++-- .../templates/workspace/Makefile | 4 +- .../cli/tests/test_cli_module_pages_keyed.py | 66 +++++++++++++++++++ skills/simple-module-creating/SKILL.md | 6 +- 14 files changed, 155 insertions(+), 68 deletions(-) rename framework/cli/simple_module_cli/templates/module/_optional/{framework_repo => standalone}/__PACKAGE__/pages/Browse.tsx.tpl (60%) rename framework/cli/simple_module_cli/templates/module/_optional/{framework_repo => standalone}/__PACKAGE__/pages/Create.tsx.tpl (73%) rename framework/cli/simple_module_cli/templates/module/_optional/{framework_repo => standalone}/__PACKAGE__/pages/Edit.tsx.tpl (76%) create mode 100644 framework/cli/tests/test_cli_module_pages_keyed.py diff --git a/CLAUDE.md b/CLAUDE.md index aa8775df1..3adb302d4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -446,7 +446,9 @@ templates `smpy create-module` / `smpy new` use (`framework/cli/simple_module_cli/templates/module/`). Change a convention there, once. The `framework_repo` variant is a template overlay (`_optional/framework_repo/`: workspace-sourced `pyproject.toml` with the -`check_metadata.py` fields, `LICENSE`, `README.md`, i18n-keyed pages). +`check_metadata.py` fields, `LICENSE`, `README.md`). Pages are i18n-keyed +everywhere except `--standalone` module repos (`_optional/standalone/`), which +have no host to generate `keys`. It generates a CRUD sample (model, DTOs, service, REST + Inertia endpoints, Browse/Create/Edit pages, `locales/en.json`, tests) whose permissions, page keys diff --git a/framework/cli/simple_module_cli/scaffolding.py b/framework/cli/simple_module_cli/scaffolding.py index 2ea241582..bff031f3b 100644 --- a/framework/cli/simple_module_cli/scaffolding.py +++ b/framework/cli/simple_module_cli/scaffolding.py @@ -220,13 +220,18 @@ def create_module( simple_module_python monorepo itself (``make new-module``): it overlays ``_optional/framework_repo/`` (a workspace-sourced ``pyproject.toml`` with the metadata ``scripts/check_metadata.py`` requires, a LICENSE and README - that pass ``check_readmes.py``, and i18n-keyed pages) and implies no - ``.github/``. Wiring into the repo's own pyproject files is + that pass ``check_readmes.py``) and implies no ``.github/``. Wiring into the repo's own pyproject files is :mod:`simple_module_cli.framework_repo`'s job. + The base pages read their strings from ``locales/en.json`` through + ``t(keys..…)`` (GH #918); the host's ``gen-i18n`` (run by + ``make install`` and every dev boot) adds the module to ``keys``. + ``standalone=True`` additionally overlays ``_optional/standalone/`` (npm devDependencies + a tsconfig that resolves ``@simple-module-py/ui`` from the repo's own ``node_modules``) so the module type-checks outside a workspace. + It also swaps in pages with literal English: a module repo has no host to + generate ``keys`` for it, so keyed pages would not type-check there. """ dest = Path(dest) existed_before = dest.exists() diff --git a/framework/cli/simple_module_cli/templates/docker/host-flat.Dockerfile b/framework/cli/simple_module_cli/templates/docker/host-flat.Dockerfile index e61ae6d2e..8c32f4c1c 100644 --- a/framework/cli/simple_module_cli/templates/docker/host-flat.Dockerfile +++ b/framework/cli/simple_module_cli/templates/docker/host-flat.Dockerfile @@ -32,8 +32,11 @@ RUN --mount=type=cache,target=/root/.cache/uv \ # Flat mode keeps the frontend's own package.json under client_app/. RUN cd client_app && if [ -f package-lock.json ]; then npm ci; else npm install; fi -# Page manifest + generated module imports, then the production bundle. +# Page manifest + generated module imports, the app's i18n keys (module pages +# read `keys.`, which the published @simple-module-py/i18n lacks), then +# the production bundle. RUN uv run python -m simple_module_hosting gen-pages --host-dir=client_app +RUN uv run python -m simple_module_hosting gen-i18n RUN cd client_app && npm run build # node_modules never ships in the runtime image. diff --git a/framework/cli/simple_module_cli/templates/docker/host.Dockerfile b/framework/cli/simple_module_cli/templates/docker/host.Dockerfile index 3377bbc7a..7d15cd882 100644 --- a/framework/cli/simple_module_cli/templates/docker/host.Dockerfile +++ b/framework/cli/simple_module_cli/templates/docker/host.Dockerfile @@ -36,8 +36,11 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --all-packages --no-dev -# Page manifest + generated module imports, then the production bundle. +# Page manifest + generated module imports, the app's i18n keys (module pages +# read `keys.`, which the published @simple-module-py/i18n lacks), then +# the production bundle. RUN cd host && uv run python -m simple_module_hosting gen-pages --host-dir=client_app +RUN cd host && uv run python -m simple_module_hosting gen-i18n RUN npm run build # Re-sync so hatch force-include picks up freshly built module static/dist. diff --git a/framework/cli/simple_module_cli/templates/host/Makefile b/framework/cli/simple_module_cli/templates/host/Makefile index 0ad61ae58..53585d5b0 100644 --- a/framework/cli/simple_module_cli/templates/host/Makefile +++ b/framework/cli/simple_module_cli/templates/host/Makefile @@ -23,7 +23,9 @@ dev-api: dev-ui: cd client_app && npm run dev -build: +# Module pages read `keys.` (gen-i18n); a bundle built without them +# crashes those pages at runtime, and tsc does not catch it. +build: gen-pages gen-i18n cd client_app && npm run build # Testing diff --git a/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl b/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl index 537c2f9f0..b45ed5eae 100644 --- a/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl +++ b/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl @@ -1,8 +1,9 @@ import { Head, Link, router } from '@inertiajs/react'; +import { keys, useT } from '@simple-module-py/i18n'; import { PageShell } from '@simple-module-py/ui/components/PageShell'; +import { useApiErrorToast } from '@simple-module-py/ui/hooks/use-api-error-toast'; import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout'; import { apiResult } from '@simple-module-py/ui/lib/api'; -import { useState } from 'react'; import { api } from './api'; import type { components } from './api.generated'; @@ -10,43 +11,48 @@ import type { components } from './api.generated'; type Item = components['schemas']['{{SINGULAR_CLASS}}Out']; export default function Browse({ items }: { items: Item[] }) { - const [error, setError] = useState(null); + const { t } = useT(); + const showError = useApiErrorToast(keys.{{PACKAGE_NAME}}.browse.delete_failed); + const editLabel = t(keys.{{PACKAGE_NAME}}.browse.edit_link); async function remove(item: Item) { - setError(null); const result = await apiResult( api.DELETE('/api/{{MODULE_SLUG}}/{item_id}', { params: { path: { item_id: item.id } } }), ); - if (!result.ok) { - setError(result.detail ?? 'Could not delete'); - return; - } - router.reload({ only: ['items'] }); + showError(result); + if (result.ok) router.reload({ only: ['items'] }); } return ( - - + +
- New {{SINGULAR_CLASS}} + {t(keys.{{PACKAGE_NAME}}.browse.new_button)}
- {error &&

{error}

} {items.length === 0 ? ( -

No {{PACKAGE_NAME}} yet.

+
+

{t(keys.{{PACKAGE_NAME}}.browse.empty_title)}

+

+ {t(keys.{{PACKAGE_NAME}}.browse.empty_description)} +

+
) : (
    {items.map((item) => (
  • {item.name} - Edit + {editLabel}
  • diff --git a/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl b/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl index acdd51d94..4dd28079a 100644 --- a/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl +++ b/framework/cli/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl @@ -1,12 +1,14 @@ import { Head, useForm } from '@inertiajs/react'; +import { keys, useT } from '@simple-module-py/i18n'; import { PageShell } from '@simple-module-py/ui/components/PageShell'; import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout'; export default function Create() { + const { t } = useT(); const form = useForm({ name: '', description: '' }); return ( - - + +
    { @@ -15,7 +17,7 @@ export default function Create() { }} >