mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 21:02:12 +03:00
29 lines
766 B
TypeScript
29 lines
766 B
TypeScript
import { getRequestConfig } from "next-intl/server";
|
|
import { cookies, headers } from "next/headers";
|
|
import { LOCALES, DEFAULT_LOCALE, LOCALE_COOKIE } from "./config";
|
|
import type { Locale } from "./config";
|
|
|
|
export default getRequestConfig(async () => {
|
|
// 1. Try cookie
|
|
const cookieStore = await cookies();
|
|
let locale: string = cookieStore.get(LOCALE_COOKIE)?.value || "";
|
|
|
|
// 2. Try custom header (set by middleware)
|
|
if (!locale) {
|
|
const headerStore = await headers();
|
|
locale = headerStore.get("x-locale") || "";
|
|
}
|
|
|
|
// 3. Validate & fallback
|
|
if (!LOCALES.includes(locale as Locale)) {
|
|
locale = DEFAULT_LOCALE;
|
|
}
|
|
|
|
const messages = (await import(`./messages/${locale}.json`)).default;
|
|
|
|
return {
|
|
locale,
|
|
messages,
|
|
};
|
|
});
|