diff --git a/apps/web/components/I18nLanguageHandler.tsx b/apps/web/components/I18nLanguageHandler.tsx index f7c9ba2930..8297f529de 100644 --- a/apps/web/components/I18nLanguageHandler.tsx +++ b/apps/web/components/I18nLanguageHandler.tsx @@ -1,4 +1,3 @@ -import { isEmpty } from "lodash"; import { useTranslation } from "next-i18next"; import { useEffect } from "react"; @@ -20,13 +19,13 @@ export function useViewerI18n() { /** * Auto-switches locale client-side to the logged in user's preference */ -const I18nLanguageHandler = (): null => { +const useI18nLanguageHandler = () => { const { i18n } = useTranslation("common"); const locale = useViewerI18n().data?.locale || i18n.language; useEffect(() => { // bail early when i18n = {} - if (isEmpty(i18n)) return; + 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); @@ -35,8 +34,6 @@ const I18nLanguageHandler = (): null => { document.dir = i18n.dir(); document.documentElement.setAttribute("lang", locale); }, [locale, i18n]); - - return null; }; -export default I18nLanguageHandler; +export default useI18nLanguageHandler; diff --git a/apps/web/components/PageWrapper.tsx b/apps/web/components/PageWrapper.tsx index c076ebd2da..b975cdafe7 100644 --- a/apps/web/components/PageWrapper.tsx +++ b/apps/web/components/PageWrapper.tsx @@ -13,7 +13,7 @@ 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"; +import useI18nLanguageHandler from "@components/I18nLanguageHandler"; export interface CalPageWrapper { (props?: AppProps): JSX.Element; @@ -29,6 +29,7 @@ const calFont = localFont({ }); function PageWrapper(props: AppProps) { + useI18nLanguageHandler(); const { Component, pageProps, err, router } = props; let pageStatus = "200"; @@ -72,7 +73,6 @@ function PageWrapper(props: AppProps) { } {...seoConfig.defaultNextSeo} /> -