2023-05-09 19:27:05 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
|
|
|
import type { WithLocale } from "../../createContext";
|
2023-08-19 00:46:17 +00:00
|
|
|
import type { I18nInputSchema } from "./i18n.schema";
|
2023-04-25 22:39:47 +00:00
|
|
|
|
|
|
|
type I18nOptions = {
|
2023-05-09 19:27:05 +00:00
|
|
|
ctx: WithLocale & {
|
|
|
|
req: NextApiRequest | undefined;
|
|
|
|
res: NextApiResponse | undefined;
|
|
|
|
};
|
2023-08-19 00:46:17 +00:00
|
|
|
input: I18nInputSchema;
|
2023-04-25 22:39:47 +00:00
|
|
|
};
|
|
|
|
|
2023-08-19 00:46:17 +00:00
|
|
|
export const i18nHandler = async ({ input }: I18nOptions) => {
|
|
|
|
const { locale } = input;
|
|
|
|
const { serverSideTranslations } = await import("next-i18next/serverSideTranslations");
|
|
|
|
const i18n = await serverSideTranslations(locale, ["common", "vital"]);
|
2023-04-25 22:39:47 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
i18n,
|
|
|
|
locale,
|
|
|
|
};
|
|
|
|
};
|
2023-08-24 10:19:24 +00:00
|
|
|
|
|
|
|
export default i18nHandler;
|