next-intlayer
Version:
Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.
31 lines • 882 B
JavaScript
"use client";
import { getLocalizedUrl, getPathWithoutLocale } from "intlayer";
import { useRouter } from "next/router.js";
import { useCallback, useMemo } from "react";
import { useLocale as useLocaleReact } from "react-intlayer";
const useLocalePageRouter = () => {
const { push, pathname, reload } = useRouter();
const pathWithoutLocale = useMemo(
() => getPathWithoutLocale(pathname),
[pathname]
);
const redirectionFunction = useCallback(
(locale) => {
const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
push(pathWithLocale);
return reload();
},
[reload, pathWithoutLocale]
);
const reactLocaleHook = useLocaleReact({
onLocaleChange: redirectionFunction
});
return {
...reactLocaleHook,
pathWithoutLocale
};
};
export {
useLocalePageRouter
};
//# sourceMappingURL=useLocalePageRouter.mjs.map