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.

feat(i18n): language selector, and fix two silent locale failures

Juan Denisfe3c0d77bc79
diff --git a/frontend/src/components/Sidebar.jsx b/frontend/src/components/Sidebar.jsx
index 1f584c04..b0acbd4e 100644
--- a/frontend/src/components/Sidebar.jsx
+++ b/frontend/src/components/Sidebar.jsx
@@ -7,7 +7,7 @@ import { Star, Settings, LogOut, Sun, Moon, Monitor, ChevronRight, ChevronDown,
import { api } from '../services/api';
import WorkspaceSwitcher from './WorkspaceSwitcher';
import NotificationBell from './NotificationBell';
-import { SIDEBAR_CATEGORIES, CATEGORY_LABELS, CATEGORY_LABEL_KEYS, SIDEBAR_PRESETS, getHiddenItemIds, getVisibleItems, applyWorkspaceNavPermissions } from './sidebarItems';
+import { SIDEBAR_CATEGORIES, SIDEBAR_CATEGORY_LABELS, SIDEBAR_PRESETS, getHiddenItemIds, getVisibleItems, applyWorkspaceNavPermissions } from './sidebarItems';
import { useTranslation } from 'react-i18next';
import useLabel from '../i18n/labels';
import { useContributions } from '../plugins/contributions';
@@ -384,8 +384,8 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {
<React.Fragment key={cat}>
<div className={`nav-category${isFirst ? ' nav-category--create' : ''}`}>
{isFirst
- ? <span>{t(CATEGORY_LABEL_KEYS[cat], { defaultValue: CATEGORY_LABELS[cat] })}</span>
- : t(CATEGORY_LABEL_KEYS[cat], { defaultValue: CATEGORY_LABELS[cat] })}
+ ? <span>{label(SIDEBAR_CATEGORY_LABELS[cat])}</span>
+ : label(SIDEBAR_CATEGORY_LABELS[cat])}
{isFirst && <QuickCreate variant="sidebar" />}
</div>
<nav className="nav">
diff --git a/frontend/src/components/settings/AppearanceTab.jsx b/frontend/src/components/settings/AppearanceTab.jsx
index f78fc47b..c2ff0790 100644
--- a/frontend/src/components/settings/AppearanceTab.jsx
+++ b/frontend/src/components/settings/AppearanceTab.jsx
@@ -7,6 +7,7 @@ import { RotateCcw, Upload, Store, Sparkles, LayoutGrid } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Switch } from '@/components/ui/switch';
import useSettingFocus from '../../hooks/useSettingFocus';
+import LanguageSelector from './LanguageSelector';
import ThemeGallery from './ThemeGallery';
import ThemeBrowseModal from './ThemeBrowseModal';
import ThemeStudioModal from './ThemeStudioModal';
@@ -57,6 +58,8 @@ const AppearanceTab = () => {
<p>Customize the look and feel of your dashboard</p>
</div>
+ <LanguageSelector />
+
<div {...register('appearance-theme', 'settings-card')}>
<h3>Theme</h3>
<p>Select your preferred color scheme</p>
diff --git a/frontend/src/components/settings/LanguageSelector.jsx b/frontend/src/components/settings/LanguageSelector.jsx
new file mode 100644
index 00000000..e0fe2127
--- /dev/null
+++ b/frontend/src/components/settings/LanguageSelector.jsx
@@ -0,0 +1,57 @@
+import { useTranslation } from 'react-i18next';
+import { Languages } from 'lucide-react';
+import {
+ Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
+} from '@/components/ui/select';
+import { useLocale } from '../../contexts/LocaleContext';
+import useSettingFocus from '../../hooks/useSettingFocus';
+
+/**
+ * Panel language (plan 79 B3).
+ *
+ * Lives next to the theme picker because it is the same shape of choice: a
+ * per-user preference that changes how every screen reads. It also persists
+ * the same way — immediately to localStorage so the sign-in screen honours it
+ * before anyone is authenticated, and to the user row so it survives a
+ * different browser.
+ *
+ * Built on ui/select rather than a hand-rolled dropdown, so it inherits the
+ * keyboard and focus behaviour of every other select in the panel.
+ */
+const LanguageSelector = () => {
+ const { t } = useTranslation();
+ const { language, setLanguage, languages } = useLocale();
+ const register = useSettingFocus();
+
+ return (
+ <div {...register('appearance-language', 'settings-card')}>
+ <h3>
+ <Languages size={16} aria-hidden="true" /> {t('settings.language.title', 'Language')}
+ </h3>
+ <p>{t('settings.language.description', 'The language used across the panel.')}</p>
+
+ <Select value={language} onValueChange={setLanguage}>
+ <SelectTrigger
+ className="settings-select"
+ aria-label={t('settings.language.title', 'Language')}
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {languages.map((entry) => (
+ <SelectItem key={entry.code} value={entry.code}>
+ {entry.nativeName}
+ {entry.name !== entry.nativeName && ` — ${entry.name}`}
+ {/* Machine-translated locales say so rather than
+ letting a rough translation read as finished. */}
+ {entry.status === 'provisional'
+ && ` (${t('settings.language.provisional', 'in progress')})`}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ );
+};
+
+export default LanguageSelector;
diff --git a/frontend/src/components/sidebarItems.js b/frontend/src/components/sidebarItems.js
index fd844efb..d4c1a963 100644
--- a/frontend/src/components/sidebarItems.js
+++ b/frontend/src/components/sidebarItems.js
@@ -16,22 +16,25 @@ const groupPrefixes = (tabs) => tabs.map((t) => t.to);
export const SIDEBAR_CATEGORIES = ['overview', 'infrastructure', 'operations', 'system'];
-// Category headings. Keys resolve at RENDER, not at import: a label
-// translated at module load would translate once and never follow a locale
-// switch (plan 79 §E).
-export const CATEGORY_LABELS = {
- overview: 'Overview',
- infrastructure: 'Infrastructure',
- operations: 'Operations',
- system: 'System'
+// Category headings. Key and English default sit in ONE object per category:
+// two parallel maps (labels here, keys there) are not sibling properties, so
+// the extractor cannot pair them and the keys never reach en.json -- which is
+// exactly how these headings stayed English in every locale until the locale
+// probe caught it.
+//
+// Keys resolve at RENDER, not at import: a label translated at module load
+// would translate once and never follow a locale switch (plan 79 §E).
+export const SIDEBAR_CATEGORY_LABELS = {
+ overview: { labelKey: 'nav.category.overview', label: 'Overview' },
+ infrastructure: { labelKey: 'nav.category.infrastructure', label: 'Infrastructure' },
+ operations: { labelKey: 'nav.category.operations', label: 'Operations' },
+ system: { labelKey: 'nav.category.system', label: 'System' }
};
-export const CATEGORY_LABEL_KEYS = {
- overview: 'nav.category.overview',
- infrastructure: 'nav.category.infrastructure',
- operations: 'nav.category.operations',
- system: 'nav.category.system'
-};
+// Plain English map, for the few callers that only need a string.
+export const CATEGORY_LABELS = Object.fromEntries(
+ Object.entries(SIDEBAR_CATEGORY_LABELS).map(([key, entry]) => [key, entry.label]),
+);
export const SIDEBAR_ITEMS = [
{
diff --git a/frontend/src/data/settingsIndex.js b/frontend/src/data/settingsIndex.js
index 0739745a..67273e1b 100644
--- a/frontend/src/data/settingsIndex.js
+++ b/frontend/src/data/settingsIndex.js
@@ -33,6 +33,7 @@ export const SETTINGS_INDEX = [
{ id: 'notifications-email-smtp', label: 'Email SMTP configuration', description: 'Set up SMTP server for sending email notifications', keywords: 'smtp email server notifications', tab: 'notifications', adminOnly: true },
{ id: 'notifications-webhook', label: 'Generic notification webhook', description: 'Send notifications to a custom webhook endpoint', keywords: 'webhook generic json payload', tab: 'notifications', adminOnly: true },
+ { id: 'appearance-language', labelKey: 'settings.language.title', label: 'Language', descriptionKey: 'settings.language.description', description: 'The language used across the panel.', keywords: 'language locale translation idioma english spanish', tab: 'appearance', adminOnly: false },
{ id: 'appearance-theme', label: 'Theme mode', description: 'Choose between dark, light, or system default theme', keywords: 'theme dark light system mode', tab: 'appearance', adminOnly: false },
{ id: 'appearance-theme-gallery', label: 'Color theme', description: 'Pick a color theme from the gallery (Paper, Nord Deep, Gruvbox, Phosphor, High Contrast)', keywords: 'theme color skin gallery paper nord gruvbox phosphor high contrast palette', tab: 'appearance', adminOnly: false },
{ id: 'appearance-accent-color', label: 'Accent color', description: 'Select the primary accent color for the UI', keywords: 'color accent primary indigo ocean forest sunset rose', tab: 'appearance', adminOnly: false },
diff --git a/frontend/src/i18n/index.js b/frontend/src/i18n/index.js
index bfbb6643..02326f15 100644
--- a/frontend/src/i18n/index.js
+++ b/frontend/src/i18n/index.js
@@ -20,13 +20,19 @@ import { initReactI18next } from 'react-i18next';
import en from './locales/en.json' with { type: 'json' };
import { DEFAULT_LANGUAGE, SUPPORTED_CODES } from './resolveLocale';
-// Statically analysable by Vite; guarded so this module can be imported by
-// node-side tooling (which has no import.meta.glob) without exploding.
-// `en` is excluded: it is statically imported above and belongs in the main
-// chunk. Globbing it too would make rollup emit it both ways for no benefit.
-const localeModules = typeof import.meta.glob === 'function'
- ? import.meta.glob(['./locales/*.json', '!./locales/en.json'])
- : {};
+// Vite REPLACES this call at build time with a map of
+// './locales/<code>.json' -> () => import(…). It must be a BARE call.
+//
+// A runtime guard around it — `typeof import.meta.glob === 'function' ? … : {}`
+// — looks defensive and is always false in the browser: there is no such
+// function, only the compile-time transform. The guard therefore threw every
+// locale away and silently fell back to English for all of them. It shipped
+// that way for one commit; probe-locale.mjs is what caught it.
+//
+// `en` is matched too and simply never loaded (it is statically imported above
+// and belongs in the main chunk). Rollup notes that as INEFFECTIVE_DYNAMIC_
+// IMPORT, which is the correct outcome, not a problem to silence.
+const localeModules = import.meta.glob('./locales/*.json');
const loaded = new Set([DEFAULT_LANGUAGE]);
diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json
index 58f336c5..b851fdf3 100644
--- a/frontend/src/i18n/locales/en.json
+++ b/frontend/src/i18n/locales/en.json
@@ -112,6 +112,12 @@
"appearance": "Appearance",
"backups": "Backups",
"brand": "Brand",
+ "category": {
+ "infrastructure": "Infrastructure",
+ "operations": "Operations",
+ "overview": "Overview",
+ "system": "System"
+ },
"closeMenu": "Close navigation menu",
"collapseGroup": "Collapse {{group}}",
"cron": "Cron Jobs",
@@ -202,6 +208,13 @@
},
"label": "Command palette"
},
+ "settings": {
+ "language": {
+ "description": "The language used across the panel.",
+ "provisional": "in progress",
+ "title": "Language"
+ }
+ },
"setup": {
"subtitle": "Let’s get your server ready",
"welcome": "Welcome to {{panel}}"
diff --git a/frontend/src/i18n/locales/es.json b/frontend/src/i18n/locales/es.json
index 7ca49692..a8882037 100644
--- a/frontend/src/i18n/locales/es.json
+++ b/frontend/src/i18n/locales/es.json
@@ -112,6 +112,12 @@
"appearance": "Apariencia",
"backups": "Copias de seguridad",
"brand": "Marca",
+ "category": {
+ "infrastructure": "Infraestructura",
+ "operations": "Operaciones",
+ "overview": "Resumen",
+ "system": "Sistema"
+ },
"closeMenu": "Cerrar el menú de navegación",
"collapseGroup": "Contraer {{group}}",
"cron": "Tareas programadas",
@@ -202,6 +208,13 @@
},
"label": "Paleta de comandos"
},
+ "settings": {
+ "language": {
+ "description": "El idioma que se usa en todo el panel.",
+ "provisional": "en curso",
+ "title": "Idioma"
+ }
+ },
"setup": {
"subtitle": "Vamos a dejar tu servidor listo",
"welcome": "Te damos la bienvenida a {{panel}}"