+1








30ba168fc3
Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Benny Joo <sldisek783@gmail.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Gergő Móricz <mo.geryy@gmail.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com>
24 lines
857 B
TypeScript
24 lines
857 B
TypeScript
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
import parser from "accept-language-parser";
|
|
import type { GetServerSidePropsContext, NextApiRequest } from "next";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
|
|
type Maybe<T> = T | null | undefined;
|
|
|
|
const { i18n } = require("@calcom/config/next-i18next.config");
|
|
|
|
export async function getLocaleFromRequest(
|
|
req: NextApiRequest | GetServerSidePropsContext["req"]
|
|
): Promise<string> {
|
|
const session = await getServerSession({ req });
|
|
if (session?.user?.locale) return session.user.locale;
|
|
let preferredLocale: string | null | undefined;
|
|
if (req.headers["accept-language"]) {
|
|
preferredLocale = parser.pick(i18n.locales, req.headers["accept-language"], {
|
|
loose: true,
|
|
}) as Maybe<string>;
|
|
}
|
|
return preferredLocale ?? i18n.defaultLocale;
|
|
}
|