calcom/lib/hooks/useLocale.ts
Mihai C 82e7e51fca
Setup i18n and locale detection (#712)
* feat: setup translations

* feat: i18n setup

* Update pages/settings/profile.tsx

Co-authored-by: Alex Johansson <alexander@n1s.se>

* fix: abstract locale hook

* fix: set default locale if preferred locale is not supported

* Revert "fix: set default locale if preferred locale is not supported"

This reverts commit e2a3d81371ee02a033520058a1d7d61cffeffc94.

* fix: set default locale if preferred locale is not supported

* fix: use 1 namespace and remove unnecessary logs

* fix: yarn.lock

* fix: linting errors

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Alex Johansson <alexander@n1s.se>
2021-09-23 09:49:17 +01:00

20 lines
414 B
TypeScript

import { useTranslation } from "next-i18next";
import { useEffect } from "react";
type LocaleProps = {
localeProp: string;
};
export const useLocale = (props: LocaleProps) => {
const { i18n, t } = useTranslation("common");
useEffect(() => {
(async () => await i18n.changeLanguage(props.localeProp))();
}, [i18n, props.localeProp]);
return {
i18n,
locale: props.localeProp,
t,
};
};