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>
21 lines
777 B
TypeScript
21 lines
777 B
TypeScript
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 };
|
|
}
|