next-intlayer
Version:
Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.
56 lines • 2.01 kB
JavaScript
"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 useLocale_exports = {};
__export(useLocale_exports, {
useLocale: () => useLocale
});
module.exports = __toCommonJS(useLocale_exports);
var import_core = require("@intlayer/core");
var import_navigation = require("next/navigation.js");
var import_react = require("react");
var import_react_intlayer = require("react-intlayer");
const useLocale = () => {
const { push, refresh } = (0, import_navigation.useRouter)();
const pathname = (0, import_navigation.usePathname)();
const pathWithoutLocale = (0, import_react.useMemo)(
() => (0, import_core.getPathWithoutLocale)(pathname),
[pathname]
);
const redirectionFunction = (0, import_react.useCallback)(
(locale) => {
const pathWithLocale = (0, import_core.getLocalizedUrl)(pathWithoutLocale, locale);
push(pathWithLocale);
return refresh();
},
[refresh, 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 = {
useLocale
});
//# sourceMappingURL=useLocale.cjs.map
;