This commit is contained in:
 Илья Шалонин 2025-10-29 13:43:43 +05:00
commit 8538ab969a
434 changed files with 44051 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import "server-only";
import { config } from "@repo/config";
import type { Locale } from "@repo/i18n";
import { cookies } from "next/headers";
export async function getUserLocale() {
const cookie = (await cookies()).get(config.i18n.localeCookieName);
return cookie?.value ?? config.i18n.defaultLocale;
}
export async function setLocaleCookie(locale: Locale) {
(await cookies()).set(config.i18n.localeCookieName, locale);
}

View file

@ -0,0 +1,10 @@
"use server";
import { setLocaleCookie } from "@i18n/lib/locale-cookie";
import type { Locale } from "@repo/i18n";
import { revalidatePath } from "next/cache";
export async function updateLocale(locale: Locale) {
await setLocaleCookie(locale);
revalidatePath("/");
}

View file

@ -0,0 +1,22 @@
import { getUserLocale } from "@i18n/lib/locale-cookie";
import { routing } from "@i18n/routing";
import { config } from "@repo/config";
import { getMessagesForLocale } from "@repo/i18n";
import { getRequestConfig } from "next-intl/server";
export default getRequestConfig(async ({ requestLocale }) => {
let locale = await requestLocale;
if (!locale) {
locale = await getUserLocale();
}
if (!(routing.locales.includes(locale) && config.i18n.enabled)) {
locale = routing.defaultLocale;
}
return {
locale,
messages: await getMessagesForLocale(locale),
};
});

View file

@ -0,0 +1,20 @@
import { config } from "@repo/config";
import { createNavigation } from "next-intl/navigation";
import { defineRouting } from "next-intl/routing";
export const routing = defineRouting({
locales: Object.keys(config.i18n.locales),
defaultLocale: config.i18n.defaultLocale,
localeCookie: {
name: config.i18n.localeCookieName,
},
localePrefix: config.i18n.enabled ? "always" : "never",
localeDetection: config.i18n.enabled,
});
export const {
Link: LocaleLink,
redirect: localeRedirect,
usePathname: useLocalePathname,
useRouter: useLocaleRouter,
} = createNavigation(routing);