UNPKG

next-intlayer

Version:

Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.

55 lines 2.03 kB
"use strict"; "use client"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var useLocalePageRouter_exports = {}; __export(useLocalePageRouter_exports, { useLocalePageRouter: () => useLocalePageRouter }); module.exports = __toCommonJS(useLocalePageRouter_exports); var import_intlayer = require("intlayer"); var import_router = require("next/router.js"); var import_react = require("react"); var import_react_intlayer = require("react-intlayer"); const useLocalePageRouter = () => { const { push, pathname, reload } = (0, import_router.useRouter)(); const pathWithoutLocale = (0, import_react.useMemo)( () => (0, import_intlayer.getPathWithoutLocale)(pathname), [pathname] ); const redirectionFunction = (0, import_react.useCallback)( (locale) => { const pathWithLocale = (0, import_intlayer.getLocalizedUrl)(pathWithoutLocale, locale); push(pathWithLocale); return reload(); }, [reload, pathWithoutLocale] ); const reactLocaleHook = (0, import_react_intlayer.useLocale)({ onLocaleChange: redirectionFunction }); return { ...reactLocaleHook, pathWithoutLocale }; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { useLocalePageRouter }); //# sourceMappingURL=useLocalePageRouter.cjs.map