Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(i18n): address review — reset locale readiness, typed error for bad language, correct parity test reference

Juan Denis2825c536a8ad
diff --git a/backend/app/api/auth.py b/backend/app/api/auth.py
index bd1f348a..f8448e0a 100644
--- a/backend/app/api/auth.py
+++ b/backend/app/api/auth.py
@@ -558,7 +558,7 @@ def update_current_user():
else:
language = normalize_language(raw)
if not language:
- return jsonify({'error': f'Unsupported language: {raw}'}), 400
+ raise ValidationError(f'Unsupported language: {raw}', code='auth.unsupported_language')
user.language = language
db.session.commit()
diff --git a/backend/app/utils/i18n.py b/backend/app/utils/i18n.py
index 91f3bd1a..09b99bf0 100644
--- a/backend/app/utils/i18n.py
+++ b/backend/app/utils/i18n.py
@@ -7,7 +7,7 @@ bundles for, and shipping a language means putting a JSON file next to it.
This module exists because the API has to validate what it stores: a user row
carrying a code the panel cannot render is a preference that silently does
nothing. Rather than have the backend fetch or parse the frontend at runtime,
-the list is restated here and ``tests/test_i18n_language_manifest.py`` fails
+the list is restated here and ``tests/test_user_language_preference.py`` fails
the build if the two ever disagree. Two lists with a parity test beats one list
the backend cannot see, and beats validating nothing at all.
"""
diff --git a/backend/tests/ERROR_SHAPE_CEILING b/backend/tests/ERROR_SHAPE_CEILING
index 23ca55f5..fdab865f 100644
--- a/backend/tests/ERROR_SHAPE_CEILING
+++ b/backend/tests/ERROR_SHAPE_CEILING
@@ -1 +1 @@
-1145
+1144
diff --git a/docs/MIGRATION_INVENTORY.md b/docs/MIGRATION_INVENTORY.md
index c31ea790..d0fc20c7 100644
--- a/docs/MIGRATION_INVENTORY.md
+++ b/docs/MIGRATION_INVENTORY.md
@@ -16,7 +16,7 @@ debt. Regenerate with `python scripts/generate-migration-inventory.py`.
| Routes on bare @jwt_required() | auth_required() / role decorators | 577 | 577 | REGISTERED EXCEPTION: JWT-only is the deliberate default; conversion grants API-key access and happens per route, on decision |
| HTTP statuses chosen by sniffing error text | typed errors from app.exceptions | 0 | 0 | INVARIANT at 0 - migration completed 2026-08-19 |
| API crashes swallowed without recording | app.error_reporting | 0 | 0 | INVARIANT at 0 |
-| Hand-shaped {'error': ...} bodies in app/api | typed errors + the global handler | 1145 | 1145 | migrate when touched; new endpoints raise |
+| Hand-shaped {'error': ...} bodies in app/api | typed errors + the global handler | 1144 | 1144 | migrate when touched; new endpoints raise |
| Raw subprocess calls outside the runners | app/utils/system.py runners | 24 | 24 | migrate when touched |
| Controller-boundary violations (routes doing service work) | service layer extraction | 509 | 509 | migrate when touched (first-wave ratchet) |
| raw api.* calls in pages/ | E1: useServerQuery/useServerMutation | 460 | 460 | migrate when touched |
diff --git a/frontend/src/contexts/LocaleContext.jsx b/frontend/src/contexts/LocaleContext.jsx
index 6021d782..4a5e7ba6 100644
--- a/frontend/src/contexts/LocaleContext.jsx
+++ b/frontend/src/contexts/LocaleContext.jsx
@@ -44,6 +44,10 @@ export function LocaleProvider({ children }) {
useEffect(() => {
let cancelled = false;
+ // `en` is bundled, but other locales may need a dynamic import.
+ // Reset readiness on each language change so we rerender once the
+ // bundle is active.
+ setReady(language === DEFAULT_LANGUAGE);
activateLocale(language).then((applied) => {
if (cancelled) return;
setReady(true);