
* Ends the war between tRPC and next-i18next * Locale fixes * Linting * Linting * trpc i18n (not working) (#942) * simplify i18n handler and remove redundant(?) fn check * split up viewer to a "logged in only" and "public" * wip -- skip first render Co-authored-by: Omar López <zomars@me.com> * Linting * I18n fixes * We don't need serverSideTranslations in every page anymore Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Alex Johansson <alexander@n1s.se>
19 lines
513 B
TypeScript
19 lines
513 B
TypeScript
import { useTranslation } from "next-i18next";
|
|
|
|
import { trpc } from "@lib/trpc";
|
|
|
|
/**
|
|
* Auto-switches locale client-side to the logged in user's preference
|
|
*/
|
|
const I18nLanguageHandler = (): null => {
|
|
const { i18n } = useTranslation("common");
|
|
const locale = trpc.useQuery(["viewer.i18n"]).data?.locale;
|
|
|
|
if (locale && i18n.language && i18n.language !== locale) {
|
|
if (typeof i18n.changeLanguage === "function") i18n.changeLanguage(locale);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
export default I18nLanguageHandler;
|