diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f462b330..913116880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ All notable changes to this project are documented in this file. The format is b - A `smpy new` app stays installed under plain uv commands. The workspace root now depends on the host (`-host`, a `{ workspace = true }` source), so `uv sync` at the root installs the app instead of uninstalling it. `smpy add … --path host` inside an app, where the host is a workspace member, syncs the whole workspace from the root (`uv sync --all-packages`, as `make install` does) instead of syncing `host/` alone, which removed the root's dev tools and other modules. `smpy create-module` inside an app prints the app's steps (`smpy add`, `make install`, `make migration`, `make migrate`, `make test`, restart `make dev`) instead of `uv sync --extra dev` in the module, which uninstalled the rest of the app; `--no-install` prints `make install`. An existing app can add `dependencies = ["-host"]` and `[tool.uv.sources] -host = { workspace = true }` to its root `pyproject.toml` (#916). - A module installed while `make dev` runs is reported as such. The reload keeps the import path the server started with, so its package cannot be imported until a restart; discovery used to log `No module named '.module'` with a traceback, as if the module were broken. It now logs that the entry point is installed but its package cannot be imported in this process, and to restart `make dev` (`strict` discovery still refuses it). A missing third-party import inside a module is still reported with its traceback (#915). - The SQLite expression-index warning is no longer printed on every migration. The revision hook now re-emits the indexes of new tables first and then names only expression indexes that the database does not have and the revision does not create (SQLite records index names even though it cannot reflect their definitions), so a fresh app's initial schema (which creates `ix_users_user_email_lower`) and an unrelated revision print nothing, while an expression index added to an existing table is still reported. The warning, `SM026` and the `migrate` note point to `make migrations-roundtrip-pg` only where the Makefile has it; elsewhere they say to run `make migrate` and `alembic check` against a PostgreSQL `SM_DATABASE_URL` and link the docs. `smpy new` shows the output of `uv sync`, `npm install` and alembic only when a step fails, stops after a failed initial migration, and prints "Next steps" once, at the end, listing the steps still to run (#917). +- The `Browse`, `Create` and `Edit` pages `smpy create-module` (and `smpy new`'s sample `hello` module) generates now read their text from the module's `locales/en.json` through `t(keys..…)`, like the bundled modules, so editing the catalog or adding `de.json` takes effect; delete errors use `useApiErrorToast`. The host's `gen-i18n` adds the module to `keys` (`make install` and every dev boot run it); `make build` now runs `gen-pages` and `gen-i18n` first, and the app Dockerfiles run `gen-i18n` before `npm run build`, because a bundle built without the app's keys crashes those pages at runtime. An existing app should add the same `gen-i18n` step to its Dockerfile before switching its pages. A `--standalone` module repo keeps literal English pages, since it has no host to generate keys (#918). ## [0.0.45] — 2026-11-11 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/docs/guide/first-module.md b/docs/guide/first-module.md index 31938be50..143e5cf66 100644 --- a/docs/guide/first-module.md +++ b/docs/guide/first-module.md @@ -246,7 +246,7 @@ async def create_order(data: OrderCreate, service: OrderServiceDep) -> OrderOut: `pages/Browse.tsx` was scaffolded — extend it: ```tsx -import { useT } from "@simple-module-py/i18n"; +import { keys, useT } from "@simple-module-py/i18n"; import { PageShell } from "@simple-module-py/ui/components/PageShell"; import { Table, @@ -261,14 +261,14 @@ import type { OrderOut } from "../contracts"; export default function Browse({ orders }: { orders: OrderOut[] }) { const { t } = useT(); return ( - + # - {t("orders.fields.customer")} - {t("orders.fields.total")} - {t("orders.fields.status")} + {t(keys.orders.fields.customer)} + {t(keys.orders.fields.total)} + {t(keys.orders.fields.status)} @@ -287,7 +287,7 @@ export default function Browse({ orders }: { orders: OrderOut[] }) { } ``` -Translations (`orders/locales/en.json`): +Translations (`orders/locales/en.json`). `keys.orders.*` is generated from this file by `make gen-i18n`, which `make install`, `make build` and every dev boot run, so a new key needs one of them before `tsc` sees it: ```json { diff --git a/docs/module-authoring.md b/docs/module-authoring.md index a94581407..0aa209463 100644 --- a/docs/module-authoring.md +++ b/docs/module-authoring.md @@ -852,7 +852,8 @@ survive a real host build (Vite import resolution, Tailwind scanning, the `gen-pages` CSS emission). `verify` answers that by scaffolding a throwaway host into `.smpy/verify-host/` (cached, gitignored), installing your module into it as an editable path dependency, and running the host's -real `gen-pages` + `npm run build`: +real `gen-pages`, `gen-i18n` (so pages that read `keys.` type-check) +and `npm run build`: ```bash uv run smpy module verify # warm re-runs reuse the cached host diff --git a/framework/cli/simple_module_cli/module_cmd.py b/framework/cli/simple_module_cli/module_cmd.py index d53cebd82..c99fd1b89 100644 --- a/framework/cli/simple_module_cli/module_cmd.py +++ b/framework/cli/simple_module_cli/module_cmd.py @@ -50,6 +50,8 @@ def run_verify(info: ModuleInfo, *, fresh: bool = False, runner=subprocess.run) ], host, ), + # Keyed pages read `keys.`, which only the host's gen-i18n adds (GH #918). + ("gen-i18n", [uv, "run", "python", "-m", "simple_module_hosting", "gen-i18n"], host), ("frontend build (tsc + vite)", [npm, "run", "build"], client_app), ) for label, cmd, cwd in steps: diff --git a/framework/cli/simple_module_cli/scaffolding.py b/framework/cli/simple_module_cli/scaffolding.py index 2ea241582..e7b677453 100644 --- a/framework/cli/simple_module_cli/scaffolding.py +++ b/framework/cli/simple_module_cli/scaffolding.py @@ -220,13 +220,14 @@ 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 - :mod:`simple_module_cli.framework_repo`'s job. + 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. ``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. + repo's own ``node_modules``) so the module type-checks outside a workspace, + and pages with literal English: the base pages use ``t(keys..…)`` + (GH #918), and a module repo has no host whose ``gen-i18n`` adds its keys. """ 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/README.md.tpl b/framework/cli/simple_module_cli/templates/module/README.md.tpl index 475dd43b1..bf8abc532 100644 --- a/framework/cli/simple_module_cli/templates/module/README.md.tpl +++ b/framework/cli/simple_module_cli/templates/module/README.md.tpl @@ -20,6 +20,13 @@ uv run pytest ## Frontend assets (optional) +The pages read their text from `{{PACKAGE_NAME}}/locales/en.json`. Inside an +app they use `t(keys.{{PACKAGE_NAME}}.…)`; the host's `make gen-i18n` (also run +by `make install`, `make build` and each dev boot) adds this module to `keys`. +A standalone module repo has no host to generate them, so its scaffolded pages +use literal English: once the module is installed in an app, switch a string +to `t(keys.{{PACKAGE_NAME}}.browse.title)` and the like. + If this module ships TSX pages: 1. Drop them in `{{PACKAGE_NAME}}/pages/` (the scaffold created the 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() { }} >