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.

Ratchet the i18n literal census to zero

Juan Denis0cdb41caf357
diff --git a/frontend/scripts/I18N_LITERAL_CEILING b/frontend/scripts/I18N_LITERAL_CEILING
index 45a4fb75..573541ac 100644
--- a/frontend/scripts/I18N_LITERAL_CEILING
+++ b/frontend/scripts/I18N_LITERAL_CEILING
@@ -1 +1 @@
-8
+0
diff --git a/frontend/scripts/check-i18n-literals.mjs b/frontend/scripts/check-i18n-literals.mjs
index 84a4619b..bee40f9a 100644
--- a/frontend/scripts/check-i18n-literals.mjs
+++ b/frontend/scripts/check-i18n-literals.mjs
@@ -87,6 +87,12 @@ const COPY_CALLS = new Set([
]);
const TOAST_OBJECTS = new Set(['toast', 'toasts', 'sonner', 'notifications']);
+// Callees whose arguments go to the panel's error tracker, never to a screen:
+// `api.reportClientError({ message: err?.message || 'Unknown error' })`. That
+// English is for whoever reads the server log, and translating it would make
+// reports arrive in each viewer's language.
+const TELEMETRY_CALLS = new Set(['reportClientError']);
+
// Directories that hold no user-facing copy, or hold it deliberately.
const SKIP_DIRS = new Set(['__tests__', '__mocks__', 'node_modules']);
const SKIP_FILE = /\.(test|spec|stories)\.[jt]sx?$/;
@@ -110,7 +116,9 @@ function isCopy(raw) {
if (value.length < 2) return false;
if (!/[A-Za-z]/.test(value)) return false; // numbers, symbols, spacers
if (/^https?:\/\//.test(value)) return false; // URLs
- if (/^[/#.]/.test(value)) return false; // routes, selectors, anchors
+ // routes, selectors, anchors -- but ". It takes a minute." is the tail of
+ // a sentence split around an element: a dot then a space is never a selector.
+ if (/^[/#.]/.test(value) && !/^[.,;:]\s/.test(value)) return false;
if (/^[a-z0-9]+([-_.:][a-z0-9]+)+$/.test(value)) return false; // ids, css classes, keys
if (/^[A-Z0-9]+(_[A-Z0-9]+)*$/.test(value)) return false; // CONSTANT_CASE
if (/^[a-z]+$/.test(value)) return false; // bare lowercase token: 'sm', 'primary'
@@ -202,6 +210,12 @@ function collectStrings(node, out) {
// "{{x}} services", not the lone word "services" (which isCopy would drop as
// a bare lowercase token).
const HOLE = '{{x}}';
+
+// A number and its unit -- `${ms} ms`, `${pct}%`, `${size} GB` -- is a
+// measurement, not a sentence: the unit symbol is the same in every locale
+// the panel ships. Only bare SI/byte symbols qualify; a unit spelled as a
+// word ("{{x}} days", "{{x}}% cpu") is still copy.
+const UNIT_ONLY = /^(ms|s|%|[KMGT]i?B|px)$/;
function templateText(node) {
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(HOLE);
}
@@ -236,6 +250,22 @@ function leafStrings(node, out) {
}
}
+const CODE_TAGS = new Set(['code', 'pre']);
+
+/**
+ * Is this child of a <code>/<pre> the sample itself -- a log line,
+ * `S3_BUCKET=${bucket}` -- rather than a placeholder shown in its place?
+ * Only the value (a literal, or `cond && literal`) is exempt; a fallback such
+ * as `{logs || 'Waiting for logs…'}` or a ternary arm is still copy.
+ */
+function isCodeSample(element, expression) {
+ if (!CODE_TAGS.has(element.openingElement?.name?.name)) return false;
+ const value = expression.type === 'LogicalExpression' && expression.operator === '&&'
+ ? expression.right
+ : expression;
+ return value.type === 'Literal' || value.type === 'TemplateLiteral';
+}
+
const INLINE_SHAPES = new Set(['ConditionalExpression', 'LogicalExpression', 'TemplateLiteral', 'Literal']);
function censusFile(path, rel) {
@@ -263,6 +293,7 @@ function censusFile(path, rel) {
const text = String(value).trim().replace(/\s+/g, ' ');
// `${a} ${b}` is all holes: nothing in it is copy of its own.
if (text.includes(HOLE) && !/[A-Za-z]{2,}/.test(text.split(HOLE).join(' '))) return;
+ if (text.includes(HOLE) && UNIT_ONLY.test(text.split(HOLE).join('').trim())) return;
if (!isCopy(text)) return;
hits.push({ line: node.loc?.start.line ?? 0, kind, text: text.slice(0, 70) });
};
@@ -293,6 +324,7 @@ function censusFile(path, rel) {
for (const child of node.children) {
if (child.type !== 'JSXExpressionContainer') continue;
if (!INLINE_SHAPES.has(child.expression?.type)) continue;
+ if (isCodeSample(node, child.expression)) continue;
const strings = [];
leafStrings(child.expression, strings);
for (const literal of strings) record(literal, 'expr', literal.value);
@@ -326,6 +358,7 @@ function censusFile(path, rel) {
// 3. Toast / confirm arguments.
case 'CallExpression': {
const name = calleeName(node.callee);
+ if (TELEMETRY_CALLS.has(name)) return;
const object = calleeObject(node.callee);
const isCopyCall = name && COPY_CALLS.has(name)
&& (object === null || TOAST_OBJECTS.has(object) || name === 'confirm');
diff --git a/frontend/src/pages/StyleGuide.jsx b/frontend/src/pages/StyleGuide.jsx
index 990bed38..f1867817 100644
--- a/frontend/src/pages/StyleGuide.jsx
+++ b/frontend/src/pages/StyleGuide.jsx
@@ -196,7 +196,7 @@ export default function StyleGuide() {
</p>
<p className="styleguide__code-sample">
<span className="styleguide__description styleguide__description--muted">$font-mono:</span><br />
- {'const server = createApp(); // IBM Plex Mono'}
+ <code>{'const server = createApp(); // IBM Plex Mono'}</code>
</p>
</SharedCard>
diff --git a/frontend/src/styles/pages/_style-guide.scss b/frontend/src/styles/pages/_style-guide.scss
index b1ef2acb..ed9f4a71 100644
--- a/frontend/src/styles/pages/_style-guide.scss
+++ b/frontend/src/styles/pages/_style-guide.scss
@@ -26,6 +26,7 @@
&__font-sample { font-family: $font-main; margin-bottom: $space-4; }
&__code-sample { font-family: $font-mono; font-size: $text-base; }
+ &__code-sample code { font: inherit; }
&__weight-sample { margin-bottom: $space-2; }
&__token-row {