feat: add i18n support (FR/EN) to backoffice with English as default
Implement full internationalization for the Next.js backoffice: - i18n infrastructure: type-safe dictionaries (fr.ts/en.ts), cookie-based locale detection, React Context for client components, server-side translation helper - Language selector in Settings page (General tab) with cookie + DB persistence - All ~35 pages and components translated via t() / useTranslation() - Default locale set to English, French available via settings Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { fetchAllSeries, fetchLibraries, fetchSeriesStatuses, LibraryDto, SeriesDto, SeriesPageDto, getBookCoverUrl } from "../../lib/api";
|
||||
import { getServerTranslations } from "../../lib/i18n/server";
|
||||
import { MarkSeriesReadButton } from "../components/MarkSeriesReadButton";
|
||||
import { LiveSearchForm } from "../components/LiveSearchForm";
|
||||
import { Card, CardContent, OffsetPagination } from "../components/ui";
|
||||
@@ -12,6 +13,7 @@ export default async function SeriesPage({
|
||||
}: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
}) {
|
||||
const { t } = await getServerTranslations();
|
||||
const searchParamsAwaited = await searchParams;
|
||||
const libraryId = typeof searchParamsAwaited.library === "string" ? searchParamsAwaited.library : undefined;
|
||||
const searchQuery = typeof searchParamsAwaited.q === "string" ? searchParamsAwaited.q : "";
|
||||
@@ -33,39 +35,39 @@ export default async function SeriesPage({
|
||||
const series = seriesPage.items;
|
||||
const totalPages = Math.ceil(seriesPage.total / limit);
|
||||
const sortOptions = [
|
||||
{ value: "", label: "Titre" },
|
||||
{ value: "latest", label: "Ajout récent" },
|
||||
{ value: "", label: t("books.sortTitle") },
|
||||
{ value: "latest", label: t("books.sortLatest") },
|
||||
];
|
||||
|
||||
const hasFilters = searchQuery || libraryId || readingStatus || sort || seriesStatus || hasMissing;
|
||||
|
||||
const libraryOptions = [
|
||||
{ value: "", label: "Toutes les bibliothèques" },
|
||||
{ value: "", label: t("books.allLibraries") },
|
||||
...libraries.map((lib) => ({ value: lib.id, label: lib.name })),
|
||||
];
|
||||
|
||||
const statusOptions = [
|
||||
{ value: "", label: "Tous" },
|
||||
{ value: "unread", label: "Non lu" },
|
||||
{ value: "reading", label: "En cours" },
|
||||
{ value: "read", label: "Lu" },
|
||||
{ value: "", label: t("common.all") },
|
||||
{ value: "unread", label: t("status.unread") },
|
||||
{ value: "reading", label: t("status.reading") },
|
||||
{ value: "read", label: t("status.read") },
|
||||
];
|
||||
|
||||
const KNOWN_STATUSES: Record<string, string> = {
|
||||
ongoing: "En cours",
|
||||
ended: "Terminée",
|
||||
hiatus: "Hiatus",
|
||||
cancelled: "Annulée",
|
||||
upcoming: "À paraître",
|
||||
ongoing: t("seriesStatus.ongoing"),
|
||||
ended: t("seriesStatus.ended"),
|
||||
hiatus: t("seriesStatus.hiatus"),
|
||||
cancelled: t("seriesStatus.cancelled"),
|
||||
upcoming: t("seriesStatus.upcoming"),
|
||||
};
|
||||
const seriesStatusOptions = [
|
||||
{ value: "", label: "Tous les statuts" },
|
||||
{ value: "", label: t("seriesStatus.allStatuses") },
|
||||
...dbStatuses.map((s) => ({ value: s, label: KNOWN_STATUSES[s] || s })),
|
||||
];
|
||||
|
||||
const missingOptions = [
|
||||
{ value: "", label: "Tous" },
|
||||
{ value: "true", label: "Livres manquants" },
|
||||
{ value: "", label: t("common.all") },
|
||||
{ value: "true", label: t("series.missingBooks") },
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -75,7 +77,7 @@ export default async function SeriesPage({
|
||||
<svg className="w-8 h-8 text-warning" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
Séries
|
||||
{t("series.title")}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
@@ -84,12 +86,12 @@ export default async function SeriesPage({
|
||||
<LiveSearchForm
|
||||
basePath="/series"
|
||||
fields={[
|
||||
{ name: "q", type: "text", label: "Rechercher", placeholder: "Rechercher par nom de série...", className: "flex-1 w-full" },
|
||||
{ name: "library", type: "select", label: "Bibliothèque", options: libraryOptions, className: "w-full sm:w-48" },
|
||||
{ name: "status", type: "select", label: "Lecture", options: statusOptions, className: "w-full sm:w-36" },
|
||||
{ name: "series_status", type: "select", label: "Statut", options: seriesStatusOptions, className: "w-full sm:w-36" },
|
||||
{ name: "has_missing", type: "select", label: "Manquant", options: missingOptions, className: "w-full sm:w-36" },
|
||||
{ name: "sort", type: "select", label: "Tri", options: sortOptions, className: "w-full sm:w-36" },
|
||||
{ name: "q", type: "text", label: t("common.search"), placeholder: t("series.searchPlaceholder"), className: "flex-1 w-full" },
|
||||
{ name: "library", type: "select", label: t("books.library"), options: libraryOptions, className: "w-full sm:w-48" },
|
||||
{ name: "status", type: "select", label: t("series.reading"), options: statusOptions, className: "w-full sm:w-36" },
|
||||
{ name: "series_status", type: "select", label: t("editSeries.status"), options: seriesStatusOptions, className: "w-full sm:w-36" },
|
||||
{ name: "has_missing", type: "select", label: t("series.missing"), options: missingOptions, className: "w-full sm:w-36" },
|
||||
{ name: "sort", type: "select", label: t("books.sort"), options: sortOptions, className: "w-full sm:w-36" },
|
||||
]}
|
||||
/>
|
||||
</CardContent>
|
||||
@@ -97,8 +99,8 @@ export default async function SeriesPage({
|
||||
|
||||
{/* Results count */}
|
||||
<p className="text-sm text-muted-foreground mb-4">
|
||||
{seriesPage.total} séries
|
||||
{searchQuery && <> correspondant à "{searchQuery}"</>}
|
||||
{seriesPage.total} {t("series.title").toLowerCase()}
|
||||
{searchQuery && <> {t("series.matchingQuery")} "{searchQuery}"</>}
|
||||
</p>
|
||||
|
||||
{/* Series Grid */}
|
||||
@@ -119,7 +121,7 @@ export default async function SeriesPage({
|
||||
<div className="aspect-[2/3] relative bg-muted/50">
|
||||
<Image
|
||||
src={getBookCoverUrl(s.first_book_id)}
|
||||
alt={`Couverture de ${s.name}`}
|
||||
alt={t("books.coverOf", { name: s.name })}
|
||||
fill
|
||||
className="object-cover"
|
||||
unoptimized
|
||||
@@ -127,11 +129,11 @@ export default async function SeriesPage({
|
||||
</div>
|
||||
<div className="p-3">
|
||||
<h3 className="font-medium text-foreground truncate text-sm" title={s.name}>
|
||||
{s.name === "unclassified" ? "Non classé" : s.name}
|
||||
{s.name === "unclassified" ? t("books.unclassified") : s.name}
|
||||
</h3>
|
||||
<div className="flex items-center justify-between mt-1">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{s.books_read_count}/{s.book_count} lu{s.book_count !== 1 ? "s" : ""}
|
||||
{t("series.readCount", { read: String(s.books_read_count), total: String(s.book_count), plural: s.book_count !== 1 ? "s" : "" })}
|
||||
</p>
|
||||
<MarkSeriesReadButton
|
||||
seriesName={s.name}
|
||||
@@ -148,17 +150,12 @@ export default async function SeriesPage({
|
||||
s.series_status === "cancelled" ? "bg-red-500/15 text-red-600" :
|
||||
"bg-muted text-muted-foreground"
|
||||
}`}>
|
||||
{s.series_status === "ongoing" ? "En cours" :
|
||||
s.series_status === "ended" ? "Terminée" :
|
||||
s.series_status === "hiatus" ? "Hiatus" :
|
||||
s.series_status === "cancelled" ? "Annulée" :
|
||||
s.series_status === "upcoming" ? "À paraître" :
|
||||
s.series_status}
|
||||
{KNOWN_STATUSES[s.series_status] || s.series_status}
|
||||
</span>
|
||||
)}
|
||||
{s.missing_count != null && s.missing_count > 0 && (
|
||||
<span className="text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-yellow-500/15 text-yellow-600">
|
||||
{s.missing_count} manquant{s.missing_count > 1 ? "s" : ""}
|
||||
{t("series.missingCount", { count: String(s.missing_count), plural: s.missing_count > 1 ? "s" : "" })}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -183,7 +180,7 @@ export default async function SeriesPage({
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-lg">
|
||||
{hasFilters ? "Aucune série trouvée correspondant à vos filtres" : "Aucune série disponible"}
|
||||
{hasFilters ? t("series.noResults") : t("series.noSeries")}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user