2021-10-12 13:11:33 +00:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2021-10-14 10:57:49 +00:00
|
|
|
import { trpc } from "@lib/trpc";
|
2021-10-12 13:11:33 +00:00
|
|
|
|
2021-10-14 10:57:49 +00:00
|
|
|
/**
|
|
|
|
* Auto-switches locale client-side to the logged in user's preference
|
|
|
|
*/
|
|
|
|
const I18nLanguageHandler = (): null => {
|
2021-10-12 13:11:33 +00:00
|
|
|
const { i18n } = useTranslation("common");
|
2021-10-14 10:57:49 +00:00
|
|
|
const locale = trpc.useQuery(["viewer.i18n"]).data?.locale;
|
|
|
|
|
|
|
|
if (locale && i18n.language && i18n.language !== locale) {
|
|
|
|
if (typeof i18n.changeLanguage === "function") i18n.changeLanguage(locale);
|
2021-10-12 13:11:33 +00:00
|
|
|
}
|
2021-10-14 10:57:49 +00:00
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default I18nLanguageHandler;
|