* revert me later * let's see if this builds * fix dupe proc * fix: v10 works * fix type error * fix type error * fix type errors * fix more * add example procedure * spreading not needed * Update yarn.lock * Revert "revert me later" This reverts commit 0c8c15d0577e0c287223039c7b6958b2b0c12c69. Co-authored-by: Chris Bautista <chrisbautista@netflix.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
36 lines
927 B
TypeScript
36 lines
927 B
TypeScript
import { useTranslation } from "next-i18next";
|
|
import { useEffect } from "react";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
export function useViewerI18n() {
|
|
return trpc.useQuery(["viewer.public.i18n"], {
|
|
staleTime: Infinity,
|
|
/**
|
|
* i18n should never be clubbed with other queries, so that it's caching can be managed independently.
|
|
* We intend to not cache i18n query
|
|
**/
|
|
trpc: {
|
|
context: { skipBatch: true },
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Auto-switches locale client-side to the logged in user's preference
|
|
*/
|
|
const I18nLanguageHandler = (): null => {
|
|
const { i18n } = useTranslation("common");
|
|
const locale = useViewerI18n().data?.locale;
|
|
|
|
useEffect(() => {
|
|
if (locale && i18n.language && i18n.language !== locale) {
|
|
if (typeof i18n.changeLanguage === "function") i18n.changeLanguage(locale);
|
|
}
|
|
}, [locale, i18n]);
|
|
|
|
return null;
|
|
};
|
|
|
|
export default I18nLanguageHandler;
|