calcom/components/I18nLanguageHandler.tsx
Omar López cfd70172f0
Refactors useLocale (#908)
* Removes unused component

* Refactors useLocale

We don't need to pass the locale prop everywhere

* Fixes syntax error

* Adds warning for missing localeProps

* Simplify i18n utils

* Update components/I18nLanguageHandler.tsx

Co-authored-by: Mihai C <34626017+mihaic195@users.noreply.github.com>

* Type fixes

Co-authored-by: Mihai C <34626017+mihaic195@users.noreply.github.com>
2021-10-12 13:11:33 +00:00

22 lines
586 B
TypeScript

import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
interface Props {
localeProp: string;
}
const I18nLanguageHandler = ({ localeProp }: Props): null => {
const { i18n } = useTranslation("common");
const router = useRouter();
const { pathname } = router;
if (!localeProp)
console.warn(
`You may forgot to return 'localeProp' from 'getServerSideProps' or 'getStaticProps' in ${pathname}`
);
if (i18n.language !== localeProp) {
i18n.changeLanguage(localeProp);
}
return null;
};
export default I18nLanguageHandler;