diff --git a/apps/web/components/I18nLanguageHandler.tsx b/apps/web/components/I18nLanguageHandler.tsx index 2db3dcc792..29ffcd97d9 100644 --- a/apps/web/components/I18nLanguageHandler.tsx +++ b/apps/web/components/I18nLanguageHandler.tsx @@ -1,12 +1,7 @@ -import { lookup } from "bcp-47-match"; -import { useSession } from "next-auth/react"; -import { useTranslation } from "next-i18next"; -import { useEffect } from "react"; - import { CALCOM_VERSION } from "@calcom/lib/constants"; import { trpc } from "@calcom/trpc/react"; -function useViewerI18n(locale: string) { +export function useViewerI18n(locale: string) { return trpc.viewer.public.i18n.useQuery( { locale, CalComVersion: CALCOM_VERSION }, { @@ -19,46 +14,3 @@ function useViewerI18n(locale: string) { } ); } - -function useClientLocale(locales: string[]) { - const session = useSession(); - // If the user is logged in, use their locale - if (session.data?.user.locale) return session.data.user.locale; - // If the user is not logged in, use the browser locale - if (typeof window !== "undefined") { - // This is the only way I found to ensure the prefetched locale is used on first render - // FIXME: Find a better way to pick the best matching locale from the browser - return lookup(locales, window.navigator.language) || window.navigator.language; - } - // If the browser is not available, use English - return "en"; -} - -export function useClientViewerI18n(locales: string[]) { - const clientLocale = useClientLocale(locales); - return useViewerI18n(clientLocale); -} - -/** - * Auto-switches locale client-side to the logged in user's preference - */ -const I18nLanguageHandler = (props: { locales: string[] }) => { - const { locales } = props; - const { i18n } = useTranslation("common"); - const locale = useClientViewerI18n(locales).data?.locale || i18n.language; - - useEffect(() => { - // bail early when i18n = {} - if (Object.keys(i18n).length === 0) return; - // if locale is ready and the i18n.language does != locale - changeLanguage - if (locale && i18n.language !== locale) { - i18n.changeLanguage(locale); - } - // set dir="rtl|ltr" - document.dir = i18n.dir(); - document.documentElement.setAttribute("lang", locale); - }, [locale, i18n]); - return null; -}; - -export default I18nLanguageHandler; diff --git a/apps/web/components/PageWrapper.tsx b/apps/web/components/PageWrapper.tsx index 2ac8afca7c..5690b369bf 100644 --- a/apps/web/components/PageWrapper.tsx +++ b/apps/web/components/PageWrapper.tsx @@ -13,8 +13,6 @@ import type { AppProps } from "@lib/app-providers"; import AppProviders from "@lib/app-providers"; import { seoConfig } from "@lib/config/next-seo.config"; -import I18nLanguageHandler from "@components/I18nLanguageHandler"; - export interface CalPageWrapper { (props?: AppProps): JSX.Element; PageWrapper?: AppProps["Component"]["PageWrapper"]; @@ -72,7 +70,6 @@ function PageWrapper(props: AppProps) { } {...seoConfig.defaultNextSeo} /> -