UNPKG

next-intl

Version:

Internationalization (i18n) for Next.js

2 lines (1 loc) 1.2 kB
import{redirect as e,permanentRedirect as t}from"next/navigation";import{forwardRef as o}from"react";import{receiveRoutingConfig as r}from"../../routing/config.js";import n from"../../shared/use.js";import{isLocalizableHref as a,isPromise as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{serializeSearchParams as c,compileLocalizedPathname as l,applyPathnamePrefix as f,normalizeNameOrNameWithParams as s}from"./utils.js";import{jsx as p}from"react/jsx-runtime";function u(u,h){const j=r(h||{}),d=j.pathnames;function g({href:e,locale:t,...o},r){let c,l;"object"==typeof e?(c=e.pathname,l=e.params):c=e;const f=a(e),s=u(),h=i(s)?n(s):s,g=f?k({locale:t||h,href:null==d?c:{pathname:c,params:l}},null!=t||void 0):c;return p(m,{ref:r,href:"object"==typeof e?{...e,pathname:g}:g,locale:t,localeCookie:j.localeCookie,...o})}const y=o(g);function k(e,t){const{href:o,locale:r}=e;let n;return null==d?"object"==typeof o?(n=o.pathname,o.query&&(n+=c(o.query))):n=o:n=l({locale:r,...s(o),pathnames:j.pathnames}),f(n,r,j,t)}function b(e){return function(t,...o){return e(k(t),...o)}}const x=b(e),q=b(t);return{config:j,Link:y,redirect:x,permanentRedirect:q,getPathname:k}}export{u as default};