as the title refers, is there a way to pass locale to tRPC context (other than passing it as an input from useRouter hook)?
Couldn't find any information related to i18n in the docs.
Thanks.
// src/server/router/context.ts
import * as trpc from "@trpc/server";
import * as trpcNext from "@trpc/server/adapters/next";
import { Session } from "next-auth";
import { getServerAuthSession } from "../common/get-server-auth-session";
import { prisma } from "../db/client";
type CreateContextOptions = {
session: Session | null;
locale: "en" | "tr";
};
export const createContextInner = async (opts: CreateContextOptions) => {
return {
session: opts.session,
prisma,
locale: opts.locale,
};
};
export const createContext = async (
opts: trpcNext.CreateNextContextOptions,
) => {
const { req, res } = opts;
// Get the session from the server using the unstable_getServerSession wrapper function
const session = await getServerAuthSession({ req, res });
const locale = "en" // TODO: get locale from router
return await createContextInner({
session,
locale
});
};
export type Context = trpc.inferAsyncReturnType<typeof createContext>;