diff --git a/frontend/public/theme.js b/frontend/public/theme.js index f2c3678..22f002e 100644 --- a/frontend/public/theme.js +++ b/frontend/public/theme.js @@ -1,9 +1,10 @@ (function () { try { var stored = localStorage.getItem("cohaise-theme"); + var theme = stored === "light" || stored === "dark" ? stored : "system"; var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; - var theme = stored || (prefersDark ? "dark" : "light"); - if (theme === "dark") document.documentElement.classList.add("dark"); + var dark = theme === "dark" || (theme === "system" && prefersDark); + document.documentElement.classList.toggle("dark", dark); } catch (error) { void error; } diff --git a/frontend/src/components/AppShell.tsx b/frontend/src/components/AppShell.tsx index 4c8d59c..0d7d90c 100644 --- a/frontend/src/components/AppShell.tsx +++ b/frontend/src/components/AppShell.tsx @@ -2,6 +2,7 @@ import { useState } from "react"; import { NavLink, Outlet } from "react-router-dom"; import { Button, cn } from "../ui/index.js"; import { useSession } from "../lib/session.js"; +import { useI18n } from "../lib/i18n.js"; import { Avatar } from "./Avatar.js"; import { ActivityIcon, @@ -50,6 +51,7 @@ const navClass = ({ isActive }: { isActive: boolean }) => export const AppShell = () => { const { user, logout } = useSession(); + const { t } = useI18n(); const [menuOpen, setMenuOpen] = useState(false); if (!user) return null; @@ -80,7 +82,7 @@ export const AppShell = () => { return ( setMenuOpen(false)}> - {item.label} + {t(item.label)} ); }; @@ -93,7 +95,7 @@ export const AppShell = () => { {isAdmin ? ( <>

- Administration + {t("Administration")}

{ADMIN_NAV.map(renderLink)} @@ -108,7 +110,7 @@ export const AppShell = () => { diff --git a/frontend/src/components/FolderChat.tsx b/frontend/src/components/FolderChat.tsx index fbb382a..22ae76d 100644 --- a/frontend/src/components/FolderChat.tsx +++ b/frontend/src/components/FolderChat.tsx @@ -9,6 +9,8 @@ import { } from "react"; import { Button, Spinner, cn } from "../ui/index.js"; import { ApiError, api, formatDate, type ChatMember, type ChatMessage } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; +import { getLocale } from "../lib/locale.js"; import { useSession } from "../lib/session.js"; import { useConfirm } from "./confirm.js"; import { Avatar } from "./Avatar.js"; @@ -22,10 +24,10 @@ const POLL_MEMBERS_MS = 30_000; const GROUP_WINDOW_MS = 5 * 60 * 1000; const timeOf = (value: string): string => - new Date(value).toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" }); + new Date(value).toLocaleTimeString(getLocale(), { hour: "2-digit", minute: "2-digit" }); const dayOf = (value: string): string => - new Date(value).toLocaleDateString("fr-FR", { + new Date(value).toLocaleDateString(getLocale(), { weekday: "long", day: "numeric", month: "long", @@ -34,8 +36,10 @@ const dayOf = (value: string): string => const isSameDay = (a: string, b: string): boolean => new Date(a).toDateString() === new Date(b).toDateString(); -const fullName = (member: { first_name: string | null; last_name: string | null }): string => - `${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || "Compte supprimé"; +const fullName = ( + member: { first_name: string | null; last_name: string | null }, + fallback: string, +): string => `${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || fallback; const MAX_ID = (list: ChatMessage[]): number => list.reduce((max, message) => Math.max(max, message.id), 0); @@ -52,6 +56,7 @@ export interface ChatFolder { * chaque requete, l'interface ne fait que l'afficher. */ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => { + const { t } = useI18n(); const { user } = useSession(); const confirm = useConfirm(); const folderId = folder.id; @@ -114,7 +119,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( setError(null); } catch (caught) { if (!active) return; - setError(caught instanceof ApiError ? caught.message : "Chargement impossible."); + setError(caught instanceof ApiError ? caught.message : t("Chargement impossible.")); } finally { if (active) { setLoading(false); @@ -189,7 +194,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( mergeMessages([message]); setDraft(""); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : "Envoi impossible."); + setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); } finally { setSending(false); } @@ -198,9 +203,9 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( const remove = async (message: ChatMessage) => { if ( !(await confirm({ - title: "Supprimer le message", - message: "Ce message sera retiré du salon pour tout le monde.", - confirmLabel: "Supprimer", + title: t("Supprimer le message"), + message: t("Ce message sera retiré du salon pour tout le monde."), + confirmLabel: t("Supprimer"), tone: "danger", })) ) @@ -210,7 +215,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( await api.chatDeleteMessage(folderId, message.id); setMessages((previous) => previous.filter((item) => item.id !== message.id)); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : "Suppression impossible."); + setError(caught instanceof ApiError ? caught.message : t("Suppression impossible.")); } finally { setDeletingId(null); } @@ -249,11 +254,11 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( "absolute inset-y-0 left-0 z-20 flex w-64 flex-col border-r border-border bg-surface transition-transform md:static md:z-auto md:translate-x-0", membersOpen ? "translate-x-0 shadow-lg md:shadow-none" : "-translate-x-full", )} - aria-label="Membres du dossier" + aria-label={t("Membres du dossier")} >
- Membres + {t("Membres")} {members.length}
@@ -270,15 +275,17 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( />

- {fullName(member)} + {fullName(member, t("Compte supprimé"))} {member.is_self ? ( - (vous) + {t("(vous)")} ) : null}

{member.last_login_at - ? `Dernière connexion le ${formatDate(member.last_login_at)}` - : "Jamais connecté"} + ? t("Dernière connexion le {date}", { + date: formatDate(member.last_login_at), + }) + : t("Jamais connecté")}

{member.role_slug === "admin" ? Admin : null} @@ -300,7 +307,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (

- Discussion · {folder.name} + {t("Discussion · {name}", { name: folder.name })}

- Membres ayant accès à ce dossier + {t("Membres ayant accès à ce dossier")}

diff --git a/frontend/src/components/IconAction.tsx b/frontend/src/components/IconAction.tsx index 3045a2e..ffd1d79 100644 --- a/frontend/src/components/IconAction.tsx +++ b/frontend/src/components/IconAction.tsx @@ -7,12 +7,14 @@ export const IconAction = ({ onClick, isLoading = false, tone = "neutral", + badge = 0, }: { label: string; icon: ReactNode; onClick: () => void; isLoading?: boolean; tone?: "neutral" | "danger"; + badge?: number; }) => ( ); diff --git a/frontend/src/components/MediaViewer.tsx b/frontend/src/components/MediaViewer.tsx index 4b88b4f..2c34898 100644 --- a/frontend/src/components/MediaViewer.tsx +++ b/frontend/src/components/MediaViewer.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { cn } from "../ui/index.js"; import { api } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js"; export interface MediaViewerItem { @@ -29,6 +30,7 @@ const actionClass = "inline-flex items-center gap-2 rounded-md border border-white/20 bg-white/10 px-3.5 py-2 text-sm font-medium text-white transition-colors hover:bg-white/20"; const TextViewer = ({ id }: { id: string }) => { + const { t } = useI18n(); const [text, setText] = useState(null); const [failed, setFailed] = useState(false); @@ -49,8 +51,8 @@ const TextViewer = ({ id }: { id: string }) => { }; }, [id]); - if (failed) return

Lecture impossible.

; - if (text === null) return

Chargement…

; + if (failed) return

{t("Lecture impossible.")}

; + if (text === null) return

{t("Chargement…")}

; return (
       {text}
@@ -66,33 +68,37 @@ const Panel = ({
   item: MediaViewerItem;
   message: string;
   openable: boolean;
-}) => (
-  
- -
-

{item.name}

-

{message}

-
-
- {openable ? ( - - Ouvrir +}) => { + const { t } = useI18n(); + return ( + -
-); + ); +}; const Body = ({ item }: { item: MediaViewerItem }) => { + const { t } = useI18n(); const kind = kindOf(item.mime_type); if (kind === "image") { return ( @@ -124,11 +130,11 @@ const Body = ({ item }: { item: MediaViewerItem }) => { } if (kind === "text") return ; if (kind === "pdf") { - return ( - - ); + return ; } - return ; + return ( + + ); }; export const MediaViewer = ({ @@ -140,6 +146,7 @@ export const MediaViewer = ({ startIndex: number; onClose: () => void; }) => { + const { t } = useI18n(); const [index, setIndex] = useState(startIndex); const current = items[index]; @@ -169,11 +176,11 @@ export const MediaViewer = ({ href={api.downloadUrl(current.id)} download={current.name} className={controlClass} - aria-label="Télécharger" + aria-label={t("Télécharger")} > -
@@ -190,7 +197,7 @@ export const MediaViewer = ({ type="button" onClick={() => setIndex((value) => value - 1)} className={cn(controlClass, "absolute left-4 z-10")} - aria-label="Fichier précédent" + aria-label={t("Fichier précédent")} > @@ -203,7 +210,7 @@ export const MediaViewer = ({ type="button" onClick={() => setIndex((value) => value + 1)} className={cn(controlClass, "absolute right-4 z-10")} - aria-label="Fichier suivant" + aria-label={t("Fichier suivant")} > diff --git a/frontend/src/components/confirm.tsx b/frontend/src/components/confirm.tsx index b888262..ed8da6e 100644 --- a/frontend/src/components/confirm.tsx +++ b/frontend/src/components/confirm.tsx @@ -6,6 +6,7 @@ import { type ReactNode, } from "react"; import { Button } from "../ui/index.js"; +import { useI18n } from "../lib/i18n.js"; import { Modal } from "./feedback.js"; export interface ConfirmOptions { @@ -33,6 +34,7 @@ const ConfirmContext = createContext(null); * `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`. */ export const ConfirmProvider = ({ children }: { children: ReactNode }) => { + const { t } = useI18n(); const [pending, setPending] = useState(null); const confirm = useCallback( @@ -52,7 +54,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => { {children} answer(false)} >
@@ -61,7 +63,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {

diff --git a/frontend/src/components/dialogs.tsx b/frontend/src/components/dialogs.tsx index 13bcca2..fb67baf 100644 --- a/frontend/src/components/dialogs.tsx +++ b/frontend/src/components/dialogs.tsx @@ -4,9 +4,11 @@ import { ApiError, api, formatDate, + type DirectoryUser, type Folder, type FolderPermission, } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; import { Alert, Modal } from "./feedback.js"; import { TrashIcon } from "./icons.js"; @@ -35,8 +37,8 @@ export const CreateFolderDialog = ({ onClose: () => void; onCreated: () => void; }) => { + const { t } = useI18n(); const [name, setName] = useState(""); - const [description, setDescription] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); @@ -45,40 +47,34 @@ export const CreateFolderDialog = ({ setBusy(true); setError(null); try { - await api.createFolder(name, parentId, description.trim() || undefined); + await api.createFolder(name, parentId); onCreated(); } catch (caught) { - setError(messageOf(caught, "Création impossible.")); + setError(messageOf(caught, t("Création impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}> setName(event.target.value)} /> - setDescription(event.target.value)} - /> {error ? {error} : null}
@@ -95,6 +91,7 @@ export const RenameDialog = ({ onClose: () => void; onDone: () => void; }) => { + const { t } = useI18n(); const [name, setName] = useState(target.name); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); @@ -104,21 +101,21 @@ export const RenameDialog = ({ setBusy(true); setError(null); try { - if (target.type === "folder") await api.updateFolder(target.id, { name }); + if (target.type === "folder") await api.updateFolder(target.id, name); else await api.renameFile(target.id, name); onDone(); } catch (caught) { - setError(messageOf(caught, "Renommage impossible.")); + setError(messageOf(caught, t("Renommage impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}> {error} : null}
@@ -167,6 +164,7 @@ export const MoveDialog = ({ onClose: () => void; onDone: () => void; }) => { + const { t } = useI18n(); const [entries, setEntries] = useState(null); const [destination, setDestination] = useState(""); const [error, setError] = useState(null); @@ -175,7 +173,7 @@ export const MoveDialog = ({ useEffect(() => { loadTree() .then(setEntries) - .catch((caught: unknown) => setError(messageOf(caught, "Chargement des dossiers impossible."))); + .catch((caught: unknown) => setError(messageOf(caught, t("Chargement des dossiers impossible.")))); }, []); const submit = async (event: FormEvent) => { @@ -188,24 +186,24 @@ export const MoveDialog = ({ else await api.moveFile(target.id, parentId); onDone(); } catch (caught) { - setError(messageOf(caught, "Déplacement impossible.")); + setError(messageOf(caught, t("Déplacement impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}>

- Destination de {target.name}. + {t("Destination de {name}.", { name: target.name })}

{entries === null && !error ? ( - Chargement des dossiers… + {t("Chargement des dossiers…")} ) : (