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.

chore(i18n): RTL plumbing ratchet; keep the bare `t` off the Vite-only path

Juan Denis33410950e899
diff --git a/frontend/package.json b/frontend/package.json
index ea37d07f..de9a577b 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -7,12 +7,13 @@
"dev": "vite",
"build": "vite build",
"test": "node --test",
- "lint": "eslint . && node scripts/check-settings-index.mjs && node scripts/check-theme-tokens.mjs && node scripts/check-frontend-boundaries.mjs && node scripts/check-style-ownership.mjs && node scripts/check-status-one-door.mjs && node scripts/check-status-scss.mjs && node scripts/check-i18n-literals.mjs && node scripts/check-intl-door.mjs && node scripts/extract-i18n.mjs --check && node scripts/check-i18n.mjs && node ../scripts/check-html-sinks.mjs",
+ "lint": "eslint . && node scripts/check-settings-index.mjs && node scripts/check-theme-tokens.mjs && node scripts/check-frontend-boundaries.mjs && node scripts/check-style-ownership.mjs && node scripts/check-status-one-door.mjs && node scripts/check-status-scss.mjs && node scripts/check-i18n-literals.mjs && node scripts/check-intl-door.mjs && node scripts/extract-i18n.mjs --check && node scripts/check-i18n.mjs && node scripts/check-logical-properties.mjs && node ../scripts/check-html-sinks.mjs",
"lint:settings-index": "node scripts/check-settings-index.mjs",
"lint:status": "node scripts/check-status-one-door.mjs",
"lint:i18n": "node scripts/check-i18n-literals.mjs",
"lint:intl": "node scripts/check-intl-door.mjs",
"lint:locales": "node scripts/check-i18n.mjs",
+ "lint:logical": "node scripts/check-logical-properties.mjs",
"i18n:extract": "node scripts/extract-i18n.mjs",
"lint:html-sinks": "node ../scripts/check-html-sinks.mjs",
"lint:frontend-boundaries": "node scripts/check-frontend-boundaries.mjs",
diff --git a/frontend/scripts/LOGICAL_PROPERTY_CEILING b/frontend/scripts/LOGICAL_PROPERTY_CEILING
new file mode 100644
index 00000000..10232896
--- /dev/null
+++ b/frontend/scripts/LOGICAL_PROPERTY_CEILING
@@ -0,0 +1 @@
+468
diff --git a/frontend/scripts/check-logical-properties.mjs b/frontend/scripts/check-logical-properties.mjs
new file mode 100644
index 00000000..1fc82c18
--- /dev/null
+++ b/frontend/scripts/check-logical-properties.mjs
@@ -0,0 +1,117 @@
+#!/usr/bin/env node
+// Plan 79 ratchet 7 — writing-direction properties in SCSS.
+//
+// LocaleContext sets `<html dir>` from the language manifest, so the plumbing
+// for a right-to-left locale exists. What does not exist is a stylesheet that
+// can follow it: physical properties (`margin-left`, `padding-right`, bare
+// `left:` / `right:`) are anchored to the page edge and ignore `dir`, so an
+// RTL locale would render a mirrored language inside an unmirrored layout.
+//
+// This is a RATCHET, not a migration. Converting the existing population means
+// looking at every page it touches, and the plan is explicit that no RTL
+// locale ships until that happens. What the ratchet buys is that the number
+// stops growing: new code writes `margin-inline-start` and friends, so the
+// eventual conversion shrinks instead of racing the codebase.
+//
+// Usage (from frontend/):
+// node scripts/check-logical-properties.mjs # check the ceiling
+// node scripts/check-logical-properties.mjs --report # worst files first
+// node scripts/check-logical-properties.mjs --update # write current count
+
+import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
+import { dirname, extname, join, relative, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const here = dirname(fileURLToPath(import.meta.url));
+const root = resolve(here, '..');
+const stylesDir = resolve(root, 'src', 'styles');
+const ceilingFile = resolve(here, 'LOGICAL_PROPERTY_CEILING');
+
+// Direction-anchored declarations. `text-align: left/right` is included for
+// the same reason: it pins prose to a page edge that RTL moves.
+const PATTERNS = [
+ /\b(?:margin|padding|border)-(?:left|right)\s*:/g,
+ /\bborder-(?:top|bottom)-(?:left|right)-radius\s*:/g,
+ /(?:^|[\s;{])(?:left|right)\s*:/g,
+ /\btext-align\s*:\s*(?:left|right)\b/g,
+ /\bfloat\s*:\s*(?:left|right)\b/g,
+];
+
+function walk(dir) {
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
+ const path = join(dir, entry.name);
+ return entry.isDirectory() ? walk(path) : (extname(path) === '.scss' ? [path] : []);
+ });
+}
+
+export function census() {
+ const byFile = new Map();
+ for (const path of walk(stylesDir)) {
+ const rel = relative(stylesDir, path).replaceAll('\\', '/');
+ const lines = readFileSync(path, 'utf8').split(/\r?\n/);
+ let hits = 0;
+ let inBlock = false;
+ for (const line of lines) {
+ let code = line;
+ if (inBlock) {
+ const end = code.indexOf('*/');
+ if (end === -1) continue;
+ code = code.slice(end + 2);
+ inBlock = false;
+ }
+ code = code.replace(/\/\*[^*]*\*\//g, '');
+ const blockStart = code.indexOf('/*');
+ if (blockStart !== -1) { inBlock = true; code = code.slice(0, blockStart); }
+ const lineComment = code.indexOf('//');
+ if (lineComment !== -1) code = code.slice(0, lineComment);
+
+ for (const pattern of PATTERNS) {
+ hits += [...code.matchAll(pattern)].length;
+ }
+ }
+ if (hits) byFile.set(rel, hits);
+ }
+ return byFile;
+}
+
+const byFile = census();
+const count = [...byFile.values()].reduce((total, hits) => total + hits, 0);
+
+if (process.argv.includes('--update')) {
+ writeFileSync(ceilingFile, `${count}\n`);
+ console.log(`logical-property ceiling updated to ${count}`);
+ process.exit(0);
+}
+
+if (process.argv.includes('--report')) {
+ for (const [file, hits] of [...byFile].sort((a, b) => b[1] - a[1]).slice(0, 30)) {
+ console.log(` ${String(hits).padStart(4)} ${file}`);
+ }
+ console.log(`\ntotal: ${count} direction-anchored declarations in ${byFile.size} files`);
+ process.exit(0);
+}
+
+const ceiling = Number(readFileSync(ceilingFile, 'utf8').trim());
+
+if (count > ceiling) {
+ console.error('\nlogical property check failed:\n');
+ console.error(` ${count} direction-anchored declarations; the ceiling is ${ceiling}.`);
+ console.error(' Use logical properties so the rule follows <html dir>:\n');
+ console.error(' margin-left -> margin-inline-start');
+ console.error(' padding-right -> padding-inline-end');
+ console.error(' left: 0 -> inset-inline-start: 0');
+ console.error(' text-align: left -> text-align: start\n');
+ for (const [file, hits] of [...byFile].sort((a, b) => b[1] - a[1]).slice(0, 5)) {
+ console.error(` ${String(hits).padStart(4)} ${file}`);
+ }
+ console.error('');
+ process.exit(1);
+}
+
+if (ceiling - count > 20) {
+ console.error(`\nlogical-property ceiling is ${ceiling} but only ${count} remain; run`);
+ console.error(' node scripts/check-logical-properties.mjs --update\n');
+ process.exit(1);
+}
+
+console.log(`✓ logical properties: ${count} direction-anchored declarations remain ratcheted (ceiling ${ceiling}).`);
diff --git a/frontend/src/components/AppLoader.jsx b/frontend/src/components/AppLoader.jsx
index 810b34e6..951ba01e 100644
--- a/frontend/src/components/AppLoader.jsx
+++ b/frontend/src/components/AppLoader.jsx
@@ -1,4 +1,4 @@
-import { t } from '../i18n';
+import { t } from '../i18n/t';
/**
* Full-screen initial loader shown while auth/setup state is resolved.
*
diff --git a/frontend/src/components/EmptyState.jsx b/frontend/src/components/EmptyState.jsx
index a03f9aa1..48e423f0 100644
--- a/frontend/src/components/EmptyState.jsx
+++ b/frontend/src/components/EmptyState.jsx
@@ -1,6 +1,6 @@
import { Inbox } from 'lucide-react';
import { PageSkeleton } from './PageSkeleton';
-import { t } from '../i18n';
+import { t } from '../i18n/t';
/**
* `loadingVariant` names the shape of the page that is loading — see
diff --git a/frontend/src/components/ErrorBoundary.jsx b/frontend/src/components/ErrorBoundary.jsx
index 3d15e594..2492a7ab 100644
--- a/frontend/src/components/ErrorBoundary.jsx
+++ b/frontend/src/components/ErrorBoundary.jsx
@@ -1,7 +1,7 @@
import { Component } from 'react';
import { AlertTriangle, RefreshCw } from 'lucide-react';
import api from '../services/api';
-import { t } from '../i18n';
+import { t } from '../i18n/t';
// Class-based Error Boundary for catching React errors
export class ErrorBoundary extends Component {
diff --git a/frontend/src/components/ErrorState.jsx b/frontend/src/components/ErrorState.jsx
index a17ab321..ecc86aff 100644
--- a/frontend/src/components/ErrorState.jsx
+++ b/frontend/src/components/ErrorState.jsx
@@ -1,6 +1,6 @@
import { AlertTriangle, RefreshCw } from 'lucide-react';
import { Button } from '@/components/ui/button';
-import { t } from '@/i18n';
+import { t } from '@/i18n/t';
/**
* Consistent error state for pages and panels. Shows an icon, title, message,
diff --git a/frontend/src/components/MobileTopBar.jsx b/frontend/src/components/MobileTopBar.jsx
index 86e14d34..761ec575 100644
--- a/frontend/src/components/MobileTopBar.jsx
+++ b/frontend/src/components/MobileTopBar.jsx
@@ -1,5 +1,5 @@
import { Menu, X } from 'lucide-react';
-import { t } from '../i18n';
+import { t } from '../i18n/t';
import { useTheme } from '../contexts/ThemeContext';
import ServerKitLogo from './ServerKitLogo';
import NotificationBell from './NotificationBell';
diff --git a/frontend/src/components/ds/PageTopbar.jsx b/frontend/src/components/ds/PageTopbar.jsx
index d399ed45..14491397 100644
--- a/frontend/src/components/ds/PageTopbar.jsx
+++ b/frontend/src/components/ds/PageTopbar.jsx
@@ -4,7 +4,7 @@ import { MoreHorizontal } from 'lucide-react';
import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
import { cn } from '@/lib/utils';
import { useOverflowItems } from '@/hooks/useOverflowItems';
-import { t } from '@/i18n';
+import { t } from '@/i18n/t';
// The demo's page top bar (see docs/REDESIGN_MAP.md §6 decision 3): infra pages
// carry their own top bar — an icon + title, an optional routed sub-nav that
diff --git a/frontend/src/i18n/index.js b/frontend/src/i18n/index.js
index 02326f15..23304850 100644
--- a/frontend/src/i18n/index.js
+++ b/frontend/src/i18n/index.js
@@ -52,15 +52,9 @@ i18next
react: { useSuspense: false },
});
-/**
- * Translate outside React — class components (ErrorBoundary), module-level
- * tables, non-component helpers.
- *
- * A bare export rather than reaching for `i18next.t` at the call site: the
- * extractor collects bare `t(...)` calls, so a member call would leave that
- * copy out of en.json and quietly untranslatable.
- */
-export const t = (...args) => i18next.t(...args);
+// Re-exported so `@/i18n` stays a valid import for browser-only callers;
+// node-reachable modules must import '@/i18n/t' directly (see that file).
+export { t } from './t';
/**
* Make a locale's bundle available, importing it on first use.
diff --git a/frontend/src/i18n/t.js b/frontend/src/i18n/t.js
new file mode 100644
index 00000000..1ce21681
--- /dev/null
+++ b/frontend/src/i18n/t.js
@@ -0,0 +1,23 @@
+import i18next from 'i18next';
+
+/**
+ * Translate outside React — class components (ErrorBoundary), module-level
+ * helpers, the API client's error mapper.
+ *
+ * A bare export rather than reaching for `i18next.t` at the call site: the
+ * extractor collects bare `t(...)` calls, so a member call would leave that
+ * copy out of en.json and quietly untranslatable.
+ *
+ * Deliberately separate from ./index.js, which owns initialisation and the
+ * `import.meta.glob` locale map. That glob is a Vite compile-time transform
+ * and throws under plain node, so anything reachable from a node test — the
+ * API client is — must not pull it in. Importing the i18next singleton here
+ * costs nothing and keeps that path clean.
+ *
+ * Before i18next is initialised (node tooling, a crash before the provider
+ * mounts) i18next returns the supplied defaultValue, so callers still get
+ * their English.
+ */
+export const t = (...args) => i18next.t(...args);
+
+export default t;
diff --git a/frontend/src/services/api/client.js b/frontend/src/services/api/client.js
index 76ccd49a..ac233f1f 100644
--- a/frontend/src/services/api/client.js
+++ b/frontend/src/services/api/client.js
@@ -1,6 +1,6 @@
// Base HTTP client - constructor, token management, core request methods
import { workspaceStore } from '../workspaceStore.js';
-import { translateServerError } from './errorCodes';
+import { translateServerError } from './errorCodes.js';
const AUTH_EXPIRED_EVENT = 'serverkit:auth-expired';
diff --git a/frontend/src/services/api/errorCodes.js b/frontend/src/services/api/errorCodes.js
index a5828988..95b4afc6 100644
--- a/frontend/src/services/api/errorCodes.js
+++ b/frontend/src/services/api/errorCodes.js
@@ -1,4 +1,4 @@
-import { t } from '../../i18n';
+import { t } from '../../i18n/t.js';
/**
* Translate a server error by its machine code (plan 79 F1).