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:
20
apps/backoffice/lib/i18n/server.ts
Normal file
20
apps/backoffice/lib/i18n/server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { cookies } from "next/headers";
|
||||
import type { Locale } from "./types";
|
||||
import { DEFAULT_LOCALE, LOCALE_COOKIE, LOCALES } from "./types";
|
||||
import { getDictionarySync, createTranslateFunction } from "./dictionaries";
|
||||
import type { TranslateFunction } from "./dictionaries";
|
||||
|
||||
export async function getServerLocale(): Promise<Locale> {
|
||||
const cookieStore = await cookies();
|
||||
const raw = cookieStore.get(LOCALE_COOKIE)?.value;
|
||||
if (raw && LOCALES.includes(raw as Locale)) {
|
||||
return raw as Locale;
|
||||
}
|
||||
return DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
export async function getServerTranslations(): Promise<{ t: TranslateFunction; locale: Locale }> {
|
||||
const locale = await getServerLocale();
|
||||
const dict = getDictionarySync(locale);
|
||||
return { t: createTranslateFunction(dict), locale };
|
||||
}
|
||||
Reference in New Issue
Block a user