2022-07-22 17:27:06 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
import parser from "accept-language-parser";
|
|
|
|
import { IncomingMessage } from "http";
|
|
|
|
|
|
|
|
import { Maybe } from "@calcom/trpc/server";
|
|
|
|
|
|
|
|
const { i18n } = require("@calcom/config/next-i18next.config");
|
|
|
|
|
|
|
|
export function getLocaleFromHeaders(req: IncomingMessage): string {
|
|
|
|
let preferredLocale: string | null | undefined;
|
|
|
|
if (req.headers["accept-language"]) {
|
|
|
|
preferredLocale = parser.pick(i18n.locales, req.headers["accept-language"]) as Maybe<string>;
|
|
|
|
}
|
|
|
|
return preferredLocale ?? i18n.defaultLocale;
|
|
|
|
}
|
|
|
|
|
2023-01-03 10:09:05 +00:00
|
|
|
export const getDirFromLang = (locale: string | undefined) =>
|
|
|
|
locale === "ar" || locale === "he" ? "rtl" : "ltr";
|