DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(web): localize the admin user management UI (#718)
Dongyua63fa223174b
diff --git a/web/app/(admin)/admin/users/page.tsx b/web/app/(admin)/admin/users/page.tsxindex 524ce8932..4749db047 100644--- a/web/app/(admin)/admin/users/page.tsx+++ b/web/app/(admin)/admin/users/page.tsx@@ -2,6 +2,7 @@import { Fragment, useEffect, useState, useCallback } from "react";import { useRouter } from "next/navigation";+import { useTranslation } from "react-i18next";import { fetchAuthStatus } from "@/lib/auth";import {listUsers,@@ -29,10 +30,11 @@ import {} from "lucide-react";import Link from "next/link";-function formatDate(iso: string): string {+function formatDate(iso: string, language: string): string {if (!iso) return "—";try {- return new Date(iso).toLocaleDateString(undefined, {+ const locale = language.toLowerCase().startsWith("zh") ? "zh-CN" : "en-US";+ return new Date(iso).toLocaleDateString(locale, {year: "numeric",month: "short",day: "numeric",@@ -44,6 +46,7 @@ function formatDate(iso: string): string {export default function AdminUsersPage() {const router = useRouter();+ const { t, i18n } = useTranslation();const [currentUser, setCurrentUser] = useState<string | null>(null);const [users, setUsers] = useState<UserRecord[]>([]);const [loading, setLoading] = useState(true);@@ -69,11 +72,11 @@ export default function AdminUsersPage() {const data = await listUsers();setUsers(data);} catch (e) {- setError(e instanceof Error ? e.message : "Failed to load users");+ setError(e instanceof Error ? e.message : t("Failed to load users"));} finally {setLoading(false);}- }, []);+ }, [t]);useEffect(() => {fetchAuthStatus().then((status) => {@@ -108,11 +111,11 @@ export default function AdminUsersPage() {setCreateError("");const username = createUsername.trim();if (!username) {- setCreateError("Username is required.");+ setCreateError(t("Username is required."));return;}if (createPassword.length < 8) {- setCreateError("Password must be at least 8 characters.");+ setCreateError(t("Password must be at least 8 characters."));return;}setCreateSubmitting(true);@@ -121,7 +124,9 @@ export default function AdminUsersPage() {setShowCreateDialog(false);await load();} catch (e) {- setCreateError(e instanceof Error ? e.message : "Failed to create user");+ setCreateError(+ e instanceof Error ? e.message : t("Failed to create user"),+ );} finally {setCreateSubmitting(false);}@@ -157,8 +162,8 @@ export default function AdminUsersPage() {e instanceof Error? e.message: confirmTarget.kind === "delete"- ? "Failed to delete user"- : "Failed to update role",+ ? t("Failed to delete user")+ : t("Failed to update role"),);} finally {setConfirmBusy(false);@@ -186,15 +191,15 @@ export default function AdminUsersPage() {className="mb-4 inline-flex items-center gap-1.5 text-sm text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"><ArrowLeft size={16} />- Back+ {t("Back")}</Link><div className="flex items-start justify-between gap-4"><div><h1 className="font-serif text-xl font-semibold text-[var(--foreground)]">- User Management+ {t("User Management")}</h1><p className="mt-0.5 text-sm text-[var(--muted-foreground)]">- Manage registered accounts+ {t("Manage registered accounts")}</p></div><div className="flex shrink-0 items-center gap-2">@@ -205,7 +210,7 @@ export default function AdminUsersPage() {hover:bg-[var(--card)] transition-colors"><UserPlus size={14} />- Add user+ {t("Add user")}</button><buttononClick={load}@@ -219,7 +224,7 @@ export default function AdminUsersPage() {size={14}className={loading ? "animate-spin" : ""}/>- Refresh+ {t("Refresh")}</button></div></div>@@ -242,8 +247,8 @@ export default function AdminUsersPage() {type="search"value={query}onChange={(e) => setQuery(e.target.value)}- placeholder="Search users…"- aria-label="Search users"+ placeholder={t("Search users…")}+ aria-label={t("Search users")}className="w-full rounded-lg border border-[var(--border)] bg-[var(--card)] py-2 pl-9 pr-3 text-smtext-[var(--foreground)] placeholder:text-[var(--muted-foreground)]/70outline-none focus:border-[var(--ring)] transition-colors"@@ -251,8 +256,13 @@ export default function AdminUsersPage() {</div><span className="shrink-0 text-xs text-[var(--muted-foreground)]">{normalizedQuery- ? `${filteredUsers.length} of ${users.length}`- : `${users.length} ${users.length === 1 ? "user" : "users"}`}+ ? t("{{filtered}} of {{total}}", {+ filtered: filteredUsers.length,+ total: users.length,+ })+ : t(users.length === 1 ? "{{count}} user" : "{{count}} users", {+ count: users.length,+ })}</span></div>)}@@ -286,10 +296,10 @@ export default function AdminUsersPage() {className="text-[var(--muted-foreground)]/50"/><p className="mt-3 text-sm font-medium text-[var(--foreground)]">- No users yet+ {t("No users yet")}</p><p className="mt-1 text-sm text-[var(--muted-foreground)]">- Accounts you create will appear here.+ {t("Accounts you create will appear here.")}</p><buttononClick={openCreateDialog}@@ -298,7 +308,7 @@ export default function AdminUsersPage() {hover:bg-[var(--background)]/60 transition-colors"><UserPlus size={14} />- Add user+ {t("Add user")}</button></div>) : filteredUsers.length === 0 ? (@@ -309,7 +319,7 @@ export default function AdminUsersPage() {className="text-[var(--muted-foreground)]/50"/><p className="mt-3 text-sm font-medium text-[var(--foreground)]">- No users match “{query.trim()}”+ {t("No users match “{{query}}”", { query: query.trim() })}</p><buttononClick={() => setQuery("")}@@ -317,17 +327,19 @@ export default function AdminUsersPage() {text-[var(--muted-foreground)] hover:text-[var(--foreground)]hover:bg-[var(--background)]/60 transition-colors">- Clear search+ {t("Clear search")}</button></div>) : (<table className="w-full text-sm"><thead><tr className="border-b border-[var(--border)] text-left text-xs text-[var(--muted-foreground)] uppercase tracking-wider">- <th className="px-5 py-3 font-medium">Username</th>- <th className="px-5 py-3 font-medium">Role</th>- <th className="px-5 py-3 font-medium">Joined</th>- <th className="px-5 py-3 font-medium text-right">Actions</th>+ <th className="px-5 py-3 font-medium">{t("Username")}</th>+ <th className="px-5 py-3 font-medium">{t("Role")}</th>+ <th className="px-5 py-3 font-medium">{t("Joined")}</th>+ <th className="px-5 py-3 font-medium text-right">+ {t("Actions")}+ </th></tr></thead><tbody className="divide-y divide-[var(--border)]">@@ -351,7 +363,7 @@ export default function AdminUsersPage() {{user.username}{isSelf && (<span className="ml-2 text-xs font-normal text-[var(--muted-foreground)]">- (you)+ {t("(you)")}</span>)}</span>@@ -369,11 +381,14 @@ export default function AdminUsersPage() {{isAdmin && (<ShieldCheck size={11} strokeWidth={2} />)}- {isAdmin ? "Admin" : "User"}+ {isAdmin ? t("Admin") : t("User")}</span></td><td className="px-5 py-3.5 text-[var(--muted-foreground)]">- {formatDate(user.created_at)}+ {formatDate(+ user.created_at,+ i18n.resolvedLanguage ?? i18n.language,+ )}</td><td className="px-5 py-3.5"><div className="flex items-center justify-end gap-1.5">@@ -384,7 +399,7 @@ export default function AdminUsersPage() {current === user.id ? null : user.id,)}- title="Manage assignments"+ title={t("Manage assignments")}className="rounded-lg p-1.5 text-[var(--muted-foreground)]hover:bg-[var(--background)] hover:text-[var(--foreground)]transition-colors"@@ -402,10 +417,10 @@ export default function AdminUsersPage() {disabled={isSelf}title={isSelf- ? "Cannot change your own role"+ ? t("Cannot change your own role"): user.role === "admin"- ? "Demote to user"- : "Promote to admin"+ ? t("Demote to user")+ : t("Promote to admin")}className="rounded-lg p-1.5 text-[var(--muted-foreground)]hover:bg-[var(--background)] hover:text-[var(--foreground)]@@ -424,8 +439,10 @@ export default function AdminUsersPage() {disabled={isSelf}title={isSelf- ? "Cannot delete your own account"- : `Delete ${user.username}`+ ? t("Cannot delete your own account")+ : t("Delete {{username}}", {+ username: user.username,+ })}className="rounded-lg p-1.5 text-[var(--muted-foreground)]hover:bg-red-500/10 hover:text-red-500@@ -452,7 +469,7 @@ export default function AdminUsersPage() {</div><p className="mt-8 text-center text-xs text-[var(--muted-foreground)]">- DeepTutor Admin · User Management+ {t("DeepTutor Admin · User Management")}</p></div>@@ -460,25 +477,25 @@ export default function AdminUsersPage() {open={confirmTarget !== null}title={confirmTarget?.kind === "delete"- ? "Delete user"+ ? t("Delete user"): confirmTarget?.kind === "promote"- ? "Promote to admin"- : "Demote to user"+ ? t("Promote to admin")+ : t("Demote to user")}tone={confirmTarget?.kind === "delete" ? "danger" : "default"}confirmLabel={confirmTarget?.kind === "delete"- ? "Delete user"+ ? t("Delete user"): confirmTarget?.kind === "promote"- ? "Promote"- : "Demote"+ ? t("Promote")+ : t("Demote")}busyLabel={confirmTarget?.kind === "delete"- ? "Deleting…"+ ? t("Deleting…"): confirmTarget?.kind === "promote"- ? "Promoting…"- : "Demoting…"+ ? t("Promoting…")+ : t("Demoting…")}busy={confirmBusy}onConfirm={handleConfirmAction}@@ -499,17 +516,31 @@ export default function AdminUsersPage() {{confirmTarget.user.username}</p><p className="text-xs text-[var(--muted-foreground)]">- {confirmTarget.user.role === "admin" ? "Admin" : "User"} ·- joined {formatDate(confirmTarget.user.created_at)}+ {t("{{role}} · joined {{date}}", {+ role:+ confirmTarget.user.role === "admin"+ ? t("Admin")+ : t("User"),+ date: formatDate(+ confirmTarget.user.created_at,+ i18n.resolvedLanguage ?? i18n.language,+ ),+ })}</p></div></div><p className="mt-3">{confirmTarget.kind === "delete"- ? "This permanently removes the account and its assignments. This cannot be undone."+ ? t(+ "This permanently removes the account and its assignments. This cannot be undone.",+ ): confirmTarget.kind === "promote"- ? "Admins can manage users and assignments, and work in the shared main workspace."- : "They will lose access to the admin area and switch to their own assigned workspace."}+ ? t(+ "Admins can manage users and assignments, and work in the shared main workspace.",+ )+ : t(+ "They will lose access to the admin area and switch to their own assigned workspace.",+ )}</p></>)}@@ -529,21 +560,21 @@ export default function AdminUsersPage() {><div className="mb-4 flex items-center justify-between"><h2 className="text-base font-semibold text-[var(--foreground)]">- Add user+ {t("Add user")}</h2><buttontype="button"onClick={closeCreateDialog}disabled={createSubmitting}className="rounded-md p-1 text-[var(--muted-foreground)] hover:bg-[var(--background)] hover:text-[var(--foreground)] disabled:opacity-40"- aria-label="Close"+ aria-label={t("Close")}><X size={16} /></button></div><label className="mb-3 block text-xs text-[var(--muted-foreground)]">- Username (or email)+ {t("Username (or email)")}<inputtype="text"value={createUsername}@@ -556,7 +587,7 @@ export default function AdminUsersPage() {</label><label className="mb-4 block text-xs text-[var(--muted-foreground)]">- Password (≥ 8 chars)+ {t("Password (≥ 8 chars)")}<inputtype="password"value={createPassword}@@ -578,14 +609,14 @@ export default function AdminUsersPage() {disabled={createSubmitting}className="rounded-lg px-3 py-1.5 text-sm text-[var(--muted-foreground)] hover:text-[var(--foreground)] disabled:opacity-40">- Cancel+ {t("Cancel")}</button><buttontype="submit"disabled={createSubmitting}className="rounded-lg bg-[var(--foreground)] px-3 py-1.5 text-sm font-medium text-[var(--background)] hover:opacity-90 disabled:opacity-40">- {createSubmitting ? "Creating…" : "Create"}+ {createSubmitting ? t("Creating…") : t("Create")}</button></div></form>diff --git a/web/components/auth/AdminLink.tsx b/web/components/auth/AdminLink.tsxindex aaa59ac9e..416570ec1 100644--- a/web/components/auth/AdminLink.tsx+++ b/web/components/auth/AdminLink.tsx@@ -3,6 +3,7 @@import Link from "next/link";import { usePathname } from "next/navigation";import { ShieldCheck } from "lucide-react";+import { useTranslation } from "react-i18next";import { useAuthStatus } from "@/hooks/useAuthStatus";interface AdminLinkProps {@@ -11,6 +12,7 @@ interface AdminLinkProps {export function AdminLink({ collapsed = false }: AdminLinkProps) {const pathname = usePathname();+ const { t } = useTranslation();const { enabled, isAdmin } = useAuthStatus();if (!enabled || !isAdmin) return null;@@ -27,8 +29,8 @@ export function AdminLink({ collapsed = false }: AdminLinkProps) {? "bg-[var(--primary)]/10 text-[var(--primary)]": "text-[var(--muted-foreground)] hover:bg-[var(--background)]/50 hover:text-[var(--foreground)]"}`}- aria-label="Admin"- title="Admin — User Management"+ aria-label={t("Admin")}+ title={t("Admin — User Management")}><ShieldCheck size={16} strokeWidth={1.5} /></Link>@@ -46,7 +48,7 @@ export function AdminLink({ collapsed = false }: AdminLinkProps) {}`}><ShieldCheck size={16} strokeWidth={1.5} />- <span>Admin</span>+ <span>{t("Admin")}</span></Link>);}diff --git a/web/components/auth/LogoutButton.tsx b/web/components/auth/LogoutButton.tsxindex fcdd2317d..157892cb9 100644--- a/web/components/auth/LogoutButton.tsx+++ b/web/components/auth/LogoutButton.tsx@@ -2,6 +2,7 @@import { LogOut } from "lucide-react";import { useRouter } from "next/navigation";+import { useTranslation } from "react-i18next";import { logout } from "@/lib/auth";import { useAuthStatus } from "@/hooks/useAuthStatus";@@ -11,6 +12,7 @@ interface LogoutButtonProps {export function LogoutButton({ collapsed = false }: LogoutButtonProps) {const router = useRouter();+ const { t } = useTranslation();const { enabled } = useAuthStatus();if (!enabled) return null;@@ -25,8 +27,8 @@ export function LogoutButton({ collapsed = false }: LogoutButtonProps) {<buttononClick={handleLogout}className="rounded-lg p-2 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--background)]/50 hover:text-red-500"- aria-label="Sign out"- title="Sign out"+ aria-label={t("Sign out")}+ title={t("Sign out")}><LogOut size={16} strokeWidth={1.5} /></button>@@ -39,7 +41,7 @@ export function LogoutButton({ collapsed = false }: LogoutButtonProps) {className="flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13.5px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--background)]/50 hover:text-red-500"><LogOut size={16} strokeWidth={1.5} />- <span>Sign out</span>+ <span>{t("Sign out")}</span></button>);}diff --git a/web/components/common/ToastViewport.tsx b/web/components/common/ToastViewport.tsxindex 8356fc8d8..dde9b4d44 100644--- a/web/components/common/ToastViewport.tsx+++ b/web/components/common/ToastViewport.tsx@@ -2,6 +2,7 @@import { X } from "lucide-react";import { useEffect, useState } from "react";+import { useTranslation } from "react-i18next";import { subscribeNotifications, type Notification } from "@/lib/notifications";/**@@ -15,6 +16,7 @@ import { subscribeNotifications, type Notification } from "@/lib/notifications";* arrive, without barging in on whatever the user was reading.*/export default function ToastViewport() {+ const { t } = useTranslation();const [toasts, setToasts] = useState<Notification[]>([]);useEffect(() => {@@ -56,7 +58,7 @@ export default function ToastViewport() {type="button"onClick={() => dismiss(toast.id)}className="rounded p-0.5 opacity-60 transition-opacity hover:opacity-100"- aria-label="Dismiss"+ aria-label={t("Dismiss")}><X size={14} strokeWidth={1.8} /></button>diff --git a/web/components/ui/ConfirmDialog.tsx b/web/components/ui/ConfirmDialog.tsxindex 5623ceb0b..7e4ce54a2 100644--- a/web/components/ui/ConfirmDialog.tsx+++ b/web/components/ui/ConfirmDialog.tsx@@ -2,6 +2,7 @@import { useEffect, type ReactNode } from "react";import { X } from "lucide-react";+import { useTranslation } from "react-i18next";interface ConfirmDialogProps {open: boolean;@@ -30,13 +31,16 @@ export function ConfirmDialog({title,children,confirmLabel,- cancelLabel = "Cancel",+ cancelLabel,tone = "default",busy = false,busyLabel,onConfirm,onCancel,}: ConfirmDialogProps) {+ const { t } = useTranslation();+ const resolvedCancelLabel = cancelLabel ?? t("Cancel");+useEffect(() => {if (!open) return;const onKeyDown = (event: KeyboardEvent) => {@@ -71,7 +75,7 @@ export function ConfirmDialog({onClick={onCancel}disabled={busy}className="rounded-md p-1 text-[var(--muted-foreground)] hover:bg-[var(--background)] hover:text-[var(--foreground)] disabled:opacity-40"- aria-label="Close"+ aria-label={t("Close")}><X size={16} /></button>@@ -91,7 +95,7 @@ export function ConfirmDialog({autoFocusclassName="rounded-lg px-3 py-1.5 text-sm text-[var(--muted-foreground)] hover:text-[var(--foreground)] disabled:opacity-40">- {cancelLabel}+ {resolvedCancelLabel}</button><buttontype="button"diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex b9d5ccd2b..1035cbf1b 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -2665,6 +2665,50 @@"Delete “{{name}}”?": "Delete “{{name}}”?","Selected": "Selected","This conversation has no readable messages.": "This conversation has no readable messages.",+ "Admin": "Admin",+ "Admin — User Management": "Admin — User Management",+ "User Management": "User Management",+ "Manage registered accounts": "Manage registered accounts",+ "Add user": "Add user",+ "Search users…": "Search users…",+ "Search users": "Search users",+ "{{filtered}} of {{total}}": "{{filtered}} of {{total}}",+ "{{count}} user": "{{count}} user",+ "{{count}} users": "{{count}} users",+ "No users yet": "No users yet",+ "Accounts you create will appear here.": "Accounts you create will appear here.",+ "No users match “{{query}}”": "No users match “{{query}}”",+ "Clear search": "Clear search",+ "Username": "Username",+ "Role": "Role",+ "Actions": "Actions",+ "(you)": "(you)",+ "Manage assignments": "Manage assignments",+ "Cannot change your own role": "Cannot change your own role",+ "Demote to user": "Demote to user",+ "Promote to admin": "Promote to admin",+ "Cannot delete your own account": "Cannot delete your own account",+ "Delete {{username}}": "Delete {{username}}",+ "DeepTutor Admin · User Management": "DeepTutor Admin · User Management",+ "Delete user": "Delete user",+ "Promote": "Promote",+ "Demote": "Demote",+ "Deleting…": "Deleting…",+ "Promoting…": "Promoting…",+ "Demoting…": "Demoting…",+ "{{role}} · joined {{date}}": "{{role}} · joined {{date}}",+ "This permanently removes the account and its assignments. This cannot be undone.": "This permanently removes the account and its assignments. This cannot be undone.",+ "Admins can manage users and assignments, and work in the shared main workspace.": "Admins can manage users and assignments, and work in the shared main workspace.",+ "They will lose access to the admin area and switch to their own assigned workspace.": "They will lose access to the admin area and switch to their own assigned workspace.",+ "Username (or email)": "Username (or email)",+ "Password (≥ 8 chars)": "Password (≥ 8 chars)",+ "Creating…": "Creating…",+ "Username is required.": "Username is required.",+ "Password must be at least 8 characters.": "Password must be at least 8 characters.",+ "Failed to load users": "Failed to load users",+ "Failed to create user": "Failed to create user",+ "Failed to delete user": "Failed to delete user",+ "Failed to update role": "Failed to update role","My profile": "My profile","View your account and personalize your avatar": "View your account and personalize your avatar","Administrator": "Administrator",diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 07f38836b..4add6cfc0 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -2665,6 +2665,50 @@"Delete “{{name}}”?": "删除“{{name}}”?","Selected": "已选","This conversation has no readable messages.": "这条对话没有可读消息。",+ "Admin": "管理",+ "Admin — User Management": "管理员 — 用户管理",+ "User Management": "用户管理",+ "Manage registered accounts": "管理已注册账户",+ "Add user": "添加用户",+ "Search users…": "搜索用户…",+ "Search users": "搜索用户",+ "{{filtered}} of {{total}}": "{{filtered}} / {{total}}",+ "{{count}} user": "{{count}} 位用户",+ "{{count}} users": "{{count}} 位用户",+ "No users yet": "暂无用户",+ "Accounts you create will appear here.": "你创建的账户将显示在这里。",+ "No users match “{{query}}”": "没有与“{{query}}”匹配的用户",+ "Clear search": "清除搜索",+ "Username": "用户名",+ "Role": "角色",+ "Actions": "操作",+ "(you)": "(你)",+ "Manage assignments": "管理分配",+ "Cannot change your own role": "无法更改自己的角色",+ "Demote to user": "降级为普通用户",+ "Promote to admin": "提升为管理员",+ "Cannot delete your own account": "无法删除自己的账户",+ "Delete {{username}}": "删除 {{username}}",+ "DeepTutor Admin · User Management": "DeepTutor 管理后台 · 用户管理",+ "Delete user": "删除用户",+ "Promote": "提升",+ "Demote": "降级",+ "Deleting…": "正在删除…",+ "Promoting…": "正在提升…",+ "Demoting…": "正在降级…",+ "{{role}} · joined {{date}}": "{{role}} · 注册于 {{date}}",+ "This permanently removes the account and its assignments. This cannot be undone.": "这将永久删除该账户及其分配,且无法撤销。",+ "Admins can manage users and assignments, and work in the shared main workspace.": "管理员可以管理用户和分配,并在共享的主工作区中操作。",+ "They will lose access to the admin area and switch to their own assigned workspace.": "该用户将无法再访问管理区域,并切换到分配给自己的工作区。",+ "Username (or email)": "用户名(或邮箱)",+ "Password (≥ 8 chars)": "密码(至少 8 个字符)",+ "Creating…": "正在创建…",+ "Username is required.": "请输入用户名。",+ "Password must be at least 8 characters.": "密码至少需要 8 个字符。",+ "Failed to load users": "加载用户失败",+ "Failed to create user": "创建用户失败",+ "Failed to delete user": "删除用户失败",+ "Failed to update role": "更新角色失败","My profile": "个人资料","View your account and personalize your avatar": "查看账户信息并个性化你的头像","Administrator": "管理员",