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:
35
apps/backoffice/lib/i18n/dictionaries.ts
Normal file
35
apps/backoffice/lib/i18n/dictionaries.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Locale } from "./types";
|
||||
import type { TranslationKey } from "./fr";
|
||||
|
||||
const dictionaries: Record<Locale, () => Promise<Record<TranslationKey, string>>> = {
|
||||
fr: () => import("./fr").then((m) => m.default),
|
||||
en: () => import("./en").then((m) => m.default),
|
||||
};
|
||||
|
||||
export async function getDictionary(locale: Locale): Promise<Record<TranslationKey, string>> {
|
||||
return dictionaries[locale]();
|
||||
}
|
||||
|
||||
// Synchronous versions for client-side use
|
||||
import fr from "./fr";
|
||||
import en from "./en";
|
||||
|
||||
const dictionariesSync: Record<Locale, Record<TranslationKey, string>> = { fr, en };
|
||||
|
||||
export function getDictionarySync(locale: Locale): Record<TranslationKey, string> {
|
||||
return dictionariesSync[locale];
|
||||
}
|
||||
|
||||
export type TranslateFunction = (key: TranslationKey, params?: Record<string, string | number>) => string;
|
||||
|
||||
export function createTranslateFunction(dict: Record<TranslationKey, string>): TranslateFunction {
|
||||
return (key: TranslationKey, params?: Record<string, string | number>): string => {
|
||||
let value: string = dict[key] ?? key;
|
||||
if (params) {
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
value = value.replace(new RegExp(`\\{\\{${k}\\}\\}`, "g"), String(v));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user