next-intl
Advanced tools
Comparing version
@@ -78,3 +78,3 @@ import { normalizeTrailingSlash } from '../shared/utils.js'; | ||
// For domain-based routing there is no reasonable x-default | ||
!routing.domains && (routing.localePrefix.mode !== 'always' || normalizedUrl.pathname === '/'); | ||
!routing.domains || routing.domains.length === 0; | ||
if (shouldAddXDefault) { | ||
@@ -81,0 +81,0 @@ const url = new URL(getLocalizedPathname(normalizedUrl.pathname, routing.defaultLocale), normalizedUrl); |
@@ -62,3 +62,4 @@ import { NextResponse } from 'next/server'; | ||
urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol; | ||
urlObj.port = request.headers.get('x-forwarded-port') ?? ''; | ||
const redirectDomainPort = redirectDomain.split(':')[1]; | ||
urlObj.port = redirectDomainPort ?? request.headers.get('x-forwarded-port') ?? ''; | ||
} | ||
@@ -69,2 +70,3 @@ } | ||
} | ||
hasRedirected = true; | ||
return NextResponse.redirect(urlObj.toString()); | ||
@@ -78,2 +80,3 @@ } | ||
let internalTemplateName; | ||
let hasRedirected; | ||
let unprefixedInternalPathname = unprefixedExternalPathname; | ||
@@ -146,3 +149,3 @@ const pathnames = resolvedRouting.pathnames; | ||
syncCookie(request, response, locale, resolvedRouting, domain); | ||
if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) { | ||
if (!hasRedirected && resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) { | ||
response.headers.set('Link', getAlternateLinksHeaderValue({ | ||
@@ -149,0 +152,0 @@ routing: resolvedRouting, |
@@ -5,3 +5,3 @@ import { redirect, permanentRedirect } from 'next/navigation'; | ||
import use from '../../shared/use.js'; | ||
import { isLocalizableHref } from '../../shared/utils.js'; | ||
import { isLocalizableHref, isPromise } from '../../shared/utils.js'; | ||
import BaseLink from './BaseLink.js'; | ||
@@ -33,5 +33,6 @@ import { validateReceivedConfig, serializeSearchParams, compileLocalizedPathname, applyPathnamePrefix, normalizeNameOrNameWithParams } from './utils.js'; | ||
}, ref) { | ||
let pathname, params; | ||
let pathname, params, query; | ||
if (typeof href === 'object') { | ||
pathname = href.pathname; | ||
query = href.query; | ||
// @ts-expect-error -- This is ok | ||
@@ -46,3 +47,3 @@ params = href.params; | ||
const localePromiseOrValue = getLocale(); | ||
const curLocale = localePromiseOrValue instanceof Promise ? use(localePromiseOrValue) : localePromiseOrValue; | ||
const curLocale = isPromise(localePromiseOrValue) ? use(localePromiseOrValue) : localePromiseOrValue; | ||
const finalPathname = isLocalizable ? getPathname( | ||
@@ -82,4 +83,8 @@ // @ts-expect-error -- This is ok | ||
locale: curLocale, | ||
href: pathnames == null ? pathname : { | ||
href: pathnames == null ? { | ||
pathname, | ||
query | ||
} : { | ||
pathname, | ||
query, | ||
params | ||
@@ -86,0 +91,0 @@ } |
import fs from 'fs'; | ||
import path from 'path'; | ||
import { throwError } from './utils.js'; | ||
import watchFile from './watchFile.js'; | ||
@@ -12,21 +13,22 @@ function runOnce(fn) { | ||
} | ||
function createMessagesDeclaration(messagesPath) { | ||
const fullPath = path.resolve(messagesPath); | ||
if (!fs.existsSync(fullPath)) { | ||
throwError(`\`createMessagesDeclaration\` points to a non-existent file: ${fullPath}`); | ||
} | ||
if (!fullPath.endsWith('.json')) { | ||
throwError(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${fullPath}`); | ||
} | ||
// Keep this as a runtime check and don't replace | ||
// this with a constant during the build process | ||
const env = process.env['NODE_ENV'.trim()]; | ||
function createMessagesDeclaration(messagesPaths) { | ||
// Next.js can call the Next.js config multiple | ||
// times - ensure we only run once. | ||
runOnce(() => { | ||
compileDeclaration(messagesPath); | ||
if (env === 'development') { | ||
startWatching(messagesPath); | ||
for (const messagesPath of messagesPaths) { | ||
const fullPath = path.resolve(messagesPath); | ||
if (!fs.existsSync(fullPath)) { | ||
throwError(`\`createMessagesDeclaration\` points to a non-existent file: ${fullPath}`); | ||
} | ||
if (!fullPath.endsWith('.json')) { | ||
throwError(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${fullPath}`); | ||
} | ||
// Keep this as a runtime check and don't replace | ||
// this with a constant during the build process | ||
const env = process.env['NODE_ENV'.trim()]; | ||
compileDeclaration(messagesPath); | ||
if (env === 'development') { | ||
startWatching(messagesPath); | ||
} | ||
} | ||
@@ -36,6 +38,4 @@ }); | ||
function startWatching(messagesPath) { | ||
const watcher = fs.watch(messagesPath, eventType => { | ||
if (eventType === 'change') { | ||
compileDeclaration(messagesPath, true); | ||
} | ||
const watcher = watchFile(messagesPath, () => { | ||
compileDeclaration(messagesPath, true); | ||
}); | ||
@@ -42,0 +42,0 @@ process.on('exit', () => { |
@@ -9,4 +9,5 @@ import createMessagesDeclaration from './createMessagesDeclaration.js'; | ||
} | ||
if (pluginConfig.experimental?.createMessagesDeclaration) { | ||
createMessagesDeclaration(pluginConfig.experimental.createMessagesDeclaration); | ||
const messagesPathOrPaths = pluginConfig.experimental?.createMessagesDeclaration; | ||
if (messagesPathOrPaths) { | ||
createMessagesDeclaration(typeof messagesPathOrPaths === 'string' ? [messagesPathOrPaths] : messagesPathOrPaths); | ||
} | ||
@@ -13,0 +14,0 @@ return getNextConfig(pluginConfig, nextConfig); |
@@ -1,7 +0,2 @@ | ||
import validateLocales from './validateLocales.js'; | ||
function defineRouting(config) { | ||
{ | ||
validateLocales(config.locales); | ||
} | ||
return config; | ||
@@ -8,0 +3,0 @@ } |
import { cache } from 'react'; | ||
import { _createIntlFormatters, _createCache, initializeConfig } from 'use-intl/core'; | ||
import { isPromise } from '../../shared/utils.js'; | ||
import { getRequestLocale } from './RequestLocale.js'; | ||
import getRuntimeConfig from 'next-intl/config'; | ||
import validateLocale from './validateLocale.js'; | ||
@@ -33,3 +35,3 @@ // This is automatically inherited by `NextIntlClientProvider` if | ||
let result = getConfig(params); | ||
if (result instanceof Promise) { | ||
if (isPromise(result)) { | ||
result = await result; | ||
@@ -40,2 +42,5 @@ } | ||
} | ||
{ | ||
validateLocale(result.locale); | ||
} | ||
return result; | ||
@@ -42,0 +47,0 @@ } |
import { headers } from 'next/headers'; | ||
import { cache } from 'react'; | ||
import { HEADER_LOCALE_NAME } from '../../shared/constants.js'; | ||
import { isPromise } from '../../shared/utils.js'; | ||
import { getCachedRequestLocale } from './RequestLocaleCache.js'; | ||
@@ -10,3 +11,3 @@ | ||
// Compatibility with Next.js <15 | ||
return promiseOrValue instanceof Promise ? await promiseOrValue : promiseOrValue; | ||
return isPromise(promiseOrValue) ? await promiseOrValue : promiseOrValue; | ||
} | ||
@@ -13,0 +14,0 @@ const getHeaders = cache(getHeadersImpl); |
@@ -125,3 +125,7 @@ function isRelativeHref(href) { | ||
} | ||
function isPromise(value) { | ||
// https://github.com/amannn/next-intl/issues/1711 | ||
return typeof value.then === 'function'; | ||
} | ||
export { getLocaleAsPrefix, getLocalePrefix, getSortedPathnames, hasPathnamePrefixed, isLocalizableHref, matchesPathname, normalizeTrailingSlash, prefixPathname, templateToRegex, unprefixPathname }; | ||
export { getLocaleAsPrefix, getLocalePrefix, getSortedPathnames, hasPathnamePrefixed, isLocalizableHref, isPromise, matchesPathname, normalizeTrailingSlash, prefixPathname, templateToRegex, unprefixPathname }; |
@@ -1,1 +0,1 @@ | ||
import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function m({localizedPathnames:m,request:p,resolvedLocale:s,routing:c}){const f=p.nextUrl.clone(),h=a(p.headers);function i(a,t){return a.pathname=e(a.pathname),p.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,p.nextUrl.basePath)),`<${a.toString()}>; rel="alternate"; hreflang="${t}"`}function u(e,a){return m&&"object"==typeof m?r(e,m[s],m[a]):e}h&&(f.port="",f.host=h),f.protocol=p.headers.get("x-forwarded-proto")??f.protocol,f.pathname=t(f.pathname,c.locales,c.localePrefix);const d=o(c.locales,c.localePrefix,!1).flatMap((([e,a])=>{function t(e){return"/"===e?a:a+e}let o;if(c.domains){return c.domains.filter((a=>n(e,a))).map((a=>(o=new URL(f),o.port="",o.host=a.domain,o.pathname=u(f.pathname,e),e===a.defaultLocale&&"always"!==c.localePrefix.mode||(o.pathname=t(o.pathname)),i(o,e))))}{let a;a=m&&"object"==typeof m?u(f.pathname,e):f.pathname,e===c.defaultLocale&&"always"!==c.localePrefix.mode||(a=t(a)),o=new URL(a,f)}return i(o,e)}));if(!c.domains&&("always"!==c.localePrefix.mode||"/"===f.pathname)){const e=new URL(u(f.pathname,c.defaultLocale),f);d.push(i(e,"x-default"))}return d.join(", ")}export{m as default}; | ||
import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function s({localizedPathnames:s,request:m,resolvedLocale:p,routing:h}){const i=m.nextUrl.clone(),c=a(m.headers);function f(a,t){return a.pathname=e(a.pathname),m.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,m.nextUrl.basePath)),`<${a.toString()}>; rel="alternate"; hreflang="${t}"`}function u(e,a){return s&&"object"==typeof s?r(e,s[p],s[a]):e}c&&(i.port="",i.host=c),i.protocol=m.headers.get("x-forwarded-proto")??i.protocol,i.pathname=t(i.pathname,h.locales,h.localePrefix);const d=o(h.locales,h.localePrefix,!1).flatMap((([e,a])=>{function t(e){return"/"===e?a:a+e}let o;if(h.domains){return h.domains.filter((a=>n(e,a))).map((a=>(o=new URL(i),o.port="",o.host=a.domain,o.pathname=u(i.pathname,e),e===a.defaultLocale&&"always"!==h.localePrefix.mode||(o.pathname=t(o.pathname)),f(o,e))))}{let a;a=s&&"object"==typeof s?u(i.pathname,e):i.pathname,e===h.defaultLocale&&"always"!==h.localePrefix.mode||(a=t(a)),o=new URL(a,i)}return f(o,e)}));if(!h.domains||0===h.domains.length){const e=new URL(u(i.pathname,h.defaultLocale),i);d.push(f(e,"x-default"))}return d.join(", ")}export{s as default}; |
@@ -1,1 +0,1 @@ | ||
import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}return o&&(l.host=o,t.headers.get("x-forwarded-host")&&(l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol,l.port=t.headers.get("x-forwarded-port")??"")),t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V=H;const B=v.pathnames;if(B){let e;if([e,S]=h(B,H,w),S){const r=B[S],a="string"==typeof r?r:r[w];if(o(a,H))V=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==V||A){const e=p(V,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(V,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&B?B[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default}; | ||
import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}if(o&&(l.host=o,t.headers.get("x-forwarded-host"))){l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol;const e=o.split(":")[1];l.port=e??t.headers.get("x-forwarded-port")??""}return t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),V=!0,e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V,B=H;const D=v.pathnames;if(D){let e;if([e,S]=h(D,H,w),S){const r=D[S],a="string"==typeof r?r:r[w];if(o(a,H))B=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==B||A){const e=p(B,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(B,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),!V&&"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&D?D[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default}; |
@@ -1,1 +0,1 @@ | ||
import{redirect as e,permanentRedirect as o}from"next/navigation";import{forwardRef as a}from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import n from"../../shared/use.js";import{isLocalizableHref as r}from"../../shared/utils.js";import i from"./BaseLink.js";import{serializeSearchParams as m,compileLocalizedPathname as l,applyPathnamePrefix as c,normalizeNameOrNameWithParams as f}from"./utils.js";import{jsx as s}from"react/jsx-runtime";function u(u,p){const d=t(p||{}),h=d.pathnames,j="as-needed"===d.localePrefix.mode&&d.domains||void 0;function g({href:e,locale:o,...a},t){let m,l;"object"==typeof e?(m=e.pathname,l=e.params):m=e;const c=r(e),f=u(),p=f instanceof Promise?n(f):f,g=c?x({locale:o||p,href:null==h?m:{pathname:m,params:l}},null!=o||j||void 0):m;return s(i,{ref:t,defaultLocale:d.defaultLocale,href:"object"==typeof e?{...e,pathname:g}:g,locale:o,localeCookie:d.localeCookie,unprefixed:j&&c?{domains:d.domains.reduce(((e,o)=>(e[o.domain]=o.defaultLocale,e)),{}),pathname:x({locale:p,href:null==h?m:{pathname:m,params:l}},!1)}:void 0,...a})}const v=a(g);function x(e,o){const{href:a,locale:t}=e;let n;return null==h?"object"==typeof a?(n=a.pathname,a.query&&(n+=m(a.query))):n=a:n=l({locale:t,...f(a),pathnames:d.pathnames}),c(n,t,d,e.domain,o)}function y(e){return function(o,...a){return e(x(o,o.domain?void 0:j),...a)}}const L=y(e),k=y(o);return{config:d,Link:v,redirect:L,permanentRedirect:k,getPathname:x}}export{u as default}; | ||
import{redirect as e,permanentRedirect as o}from"next/navigation";import{forwardRef as a}from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import n from"../../shared/use.js";import{isLocalizableHref as r,isPromise as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{serializeSearchParams as l,compileLocalizedPathname as c,applyPathnamePrefix as f,normalizeNameOrNameWithParams as u}from"./utils.js";import{jsx as s}from"react/jsx-runtime";function p(p,d){const h=t(d||{}),j=h.pathnames,y="as-needed"===h.localePrefix.mode&&h.domains||void 0;function g({href:e,locale:o,...a},t){let l,c,f;"object"==typeof e?(l=e.pathname,f=e.query,c=e.params):l=e;const u=r(e),d=p(),g=i(d)?n(d):d,q=u?v({locale:o||g,href:null==j?l:{pathname:l,params:c}},null!=o||y||void 0):l;return s(m,{ref:t,defaultLocale:h.defaultLocale,href:"object"==typeof e?{...e,pathname:q}:q,locale:o,localeCookie:h.localeCookie,unprefixed:y&&u?{domains:h.domains.reduce(((e,o)=>(e[o.domain]=o.defaultLocale,e)),{}),pathname:v({locale:g,href:null==j?{pathname:l,query:f}:{pathname:l,query:f,params:c}},!1)}:void 0,...a})}const q=a(g);function v(e,o){const{href:a,locale:t}=e;let n;return null==j?"object"==typeof a?(n=a.pathname,a.query&&(n+=l(a.query))):n=a:n=c({locale:t,...u(a),pathnames:h.pathnames}),f(n,t,h,e.domain,o)}function x(e){return function(o,...a){return e(v(o,o.domain?void 0:y),...a)}}const L=x(e),k=x(o);return{config:h,Link:q,redirect:L,permanentRedirect:k,getPathname:v}}export{p as default}; |
@@ -1,1 +0,1 @@ | ||
import e from"fs";import t from"path";import{throwError as s}from"./utils.js";function n(n){const i=t.resolve(n);e.existsSync(i)||s(`\`createMessagesDeclaration\` points to a non-existent file: ${i}`),i.endsWith(".json")||s(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${i}`);const r=process.env["NODE_ENV".trim()];var c;c=()=>{o(n),"development"===r&&function(t){const s=e.watch(t,(e=>{"change"===e&&o(t,!0)}));process.on("exit",(()=>{s.close()}))}(n)},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",c())}function o(t,s=!1){const n=t.replace(/\.json$/,".d.json.ts");function o(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(s)return e.promises.readFile(t,"utf-8").then((t=>e.promises.writeFile(n,o(t))));const i=e.readFileSync(t,"utf-8");e.writeFileSync(n,o(i))}export{n as default}; | ||
import e from"fs";import t from"path";import{throwError as s}from"./utils.js";import o from"./watchFile.js";function n(o){var n;n=()=>{for(const n of o){const o=t.resolve(n);e.existsSync(o)||s(`\`createMessagesDeclaration\` points to a non-existent file: ${o}`),o.endsWith(".json")||s(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${o}`);const c=process.env["NODE_ENV".trim()];r(n),"development"===c&&i(n)}},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",n())}function i(e){const t=o(e,(()=>{r(e,!0)}));process.on("exit",(()=>{t.close()}))}function r(t,s=!1){const o=t.replace(/\.json$/,".d.json.ts");function n(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(s)return e.promises.readFile(t,"utf-8").then((t=>e.promises.writeFile(o,n(t))));const i=e.readFileSync(t,"utf-8");e.writeFileSync(o,n(i))}export{n as default}; |
@@ -1,1 +0,1 @@ | ||
import e from"./createMessagesDeclaration.js";import t from"./getNextConfig.js";import{warn as r}from"./utils.js";function n(n={}){const o="string"==typeof n?{requestConfig:n}:n;return function(n){return function(n,o){return null!=o?.i18n&&r("\n[next-intl] An `i18n` property was found in your Next.js config. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the Pages Router, you can refer to this example: https://next-intl.dev/examples#app-router-migration\n"),n.experimental?.createMessagesDeclaration&&e(n.experimental.createMessagesDeclaration),t(n,o)}(o,n)}}export{n as default}; | ||
import e from"./createMessagesDeclaration.js";import t from"./getNextConfig.js";import{warn as n}from"./utils.js";function r(r={}){const o="string"==typeof r?{requestConfig:r}:r;return function(r){return function(r,o){null!=o?.i18n&&n("\n[next-intl] An `i18n` property was found in your Next.js config. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the Pages Router, you can refer to this example: https://next-intl.dev/examples#app-router-migration\n");const i=r.experimental?.createMessagesDeclaration;return i&&e("string"==typeof i?[i]:i),t(r,o)}(o,r)}}export{r as default}; |
@@ -1,1 +0,1 @@ | ||
import{cache as e}from"react";import{_createIntlFormatters as t,_createCache as o,initializeConfig as n}from"use-intl/core";import{getRequestLocale as r}from"./RequestLocale.js";import i from"next-intl/config";const s=e((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const a=e((async function(e,t){let o=e({locale:t,get requestLocale(){return t?Promise.resolve(t):r()}});if(o instanceof Promise&&(o=await o),!o.locale)throw new Error("No locale was returned from `getRequestConfig`.\n\nSee https://next-intl.dev/docs/usage/configuration#i18n-request");return o})),c=e(t),m=e(o);const l=e((async function(e){const t=await a(i,e);return{...n(t),_formatters:c(m()),timeZone:t.timeZone||s()}}));export{l as default}; | ||
import{cache as e}from"react";import{_createIntlFormatters as t,_createCache as o,initializeConfig as r}from"use-intl/core";import{isPromise as n}from"../../shared/utils.js";import{getRequestLocale as i}from"./RequestLocale.js";import s from"next-intl/config";const a=e((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const c=e((async function(e,t){let o=e({locale:t,get requestLocale(){return t?Promise.resolve(t):i()}});if(n(o)&&(o=await o),!o.locale)throw new Error("No locale was returned from `getRequestConfig`.\n\nSee https://next-intl.dev/docs/usage/configuration#i18n-request");return o})),m=e(t),l=e(o);const u=e((async function(e){const t=await c(s,e);return{...r(t),_formatters:m(l()),timeZone:t.timeZone||a()}}));export{u as default}; |
@@ -1,1 +0,1 @@ | ||
import{headers as t}from"next/headers";import{cache as e}from"react";import{HEADER_LOCALE_NAME as n}from"../../shared/constants.js";import{getCachedRequestLocale as r}from"./RequestLocaleCache.js";const o=e((async function(){const e=t();return e instanceof Promise?await e:e}));const i=e((async function(){let t;try{t=(await o()).get(n)||void 0}catch(t){if(t instanceof Error&&"DYNAMIC_SERVER_USAGE"===t.digest){const e=new Error("Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `setRequestLocale` API to enable static rendering, see https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#static-rendering",{cause:t});throw e.digest=t.digest,e}throw t}return t}));async function s(){return r()||await i()}export{s as getRequestLocale}; | ||
import{headers as t}from"next/headers";import{cache as e}from"react";import{HEADER_LOCALE_NAME as n}from"../../shared/constants.js";import{isPromise as r}from"../../shared/utils.js";import{getCachedRequestLocale as o}from"./RequestLocaleCache.js";const s=e((async function(){const e=t();return r(e)?await e:e}));const i=e((async function(){let t;try{t=(await s()).get(n)||void 0}catch(t){if(t instanceof Error&&"DYNAMIC_SERVER_USAGE"===t.digest){const e=new Error("Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `setRequestLocale` API to enable static rendering, see https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#static-rendering",{cause:t});throw e.digest=t.digest,e}throw t}return t}));async function a(){return o()||await i()}export{a as getRequestLocale}; |
@@ -1,1 +0,1 @@ | ||
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(n,t){return n.replace(new RegExp(`^${t}`),"")||"/"}function e(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function r(n,t){return t===n||t.startsWith(`${n}/`)}function u(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch{return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function i(n,t){const e=u(n),r=u(t);return f(e).test(r)}function c(n,t){return"never"!==t.mode&&t.prefixes?.[n]||o(n)}function o(n){return"/"+n}function f(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp(`^${t}$`)}function s(n){return n.includes("[[...")}function l(n){return n.includes("[...")}function a(n){return n.includes("[")}function p(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!l(t)&&l(u))return-1;if(l(t)&&!l(u))return 1;if(!s(t)&&s(u))return-1;if(s(t)&&!s(u))return 1}}return 0}function h(n){return n.sort(p)}export{o as getLocaleAsPrefix,c as getLocalePrefix,h as getSortedPathnames,r as hasPathnamePrefixed,n as isLocalizableHref,i as matchesPathname,u as normalizeTrailingSlash,e as prefixPathname,f as templateToRegex,t as unprefixPathname}; | ||
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(n,t){return n.replace(new RegExp(`^${t}`),"")||"/"}function e(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function r(n,t){return t===n||t.startsWith(`${n}/`)}function u(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch{return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function i(n,t){const e=u(n),r=u(t);return f(e).test(r)}function c(n,t){return"never"!==t.mode&&t.prefixes?.[n]||o(n)}function o(n){return"/"+n}function f(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp(`^${t}$`)}function s(n){return n.includes("[[...")}function l(n){return n.includes("[...")}function a(n){return n.includes("[")}function p(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!l(t)&&l(u))return-1;if(l(t)&&!l(u))return 1;if(!s(t)&&s(u))return-1;if(s(t)&&!s(u))return 1}}return 0}function h(n){return n.sort(p)}function g(n){return"function"==typeof n.then}export{o as getLocaleAsPrefix,c as getLocalePrefix,h as getSortedPathnames,r as hasPathnamePrefixed,n as isLocalizableHref,g as isPromise,i as matchesPathname,u as normalizeTrailingSlash,e as prefixPathname,f as templateToRegex,t as unprefixPathname}; |
@@ -1,1 +0,1 @@ | ||
export default function createMessagesDeclaration(messagesPath: string): void; | ||
export default function createMessagesDeclaration(messagesPaths: Array<string>): void; |
export type PluginConfig = { | ||
requestConfig?: string; | ||
experimental?: { | ||
createMessagesDeclaration?: string; | ||
/** A path to the messages file that you'd like to create a declaration for. In case you want to consider multiple files, you can pass an array of paths. */ | ||
createMessagesDeclaration?: string | Array<string>; | ||
}; | ||
}; |
import { createFormatter } from 'use-intl/core'; | ||
declare function getFormatterCachedImpl(config: Parameters<typeof createFormatter>[0]): { | ||
dateTime: (value: Date | number, formatOrOptions?: string | import("use-intl/core").DateTimeFormatOptions) => string; | ||
number: (value: number | bigint, formatOrOptions?: string | import("use-intl/core").NumberFormatOptions) => string; | ||
relativeTime: (date: number | Date, nowOrOptions?: import("use-intl/core").RelativeTimeFormatOptions["now"] | import("use-intl/core").RelativeTimeFormatOptions) => string; | ||
list: <Value extends string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, formatOrOptions?: string | Intl.ListFormatOptions) => Value extends string ? string : Iterable<import("react").ReactElement>; | ||
dateTimeRange: (start: Date | number, end: Date | number, formatOrOptions?: string | import("use-intl/core").DateTimeFormatOptions) => string; | ||
dateTime: { | ||
(value: Date | number, options?: import("use-intl/core").DateTimeFormatOptions): string; | ||
(value: Date | number, format?: string, options?: import("use-intl/core").DateTimeFormatOptions): string; | ||
}; | ||
number: { | ||
(value: number | bigint, options?: import("use-intl/core").NumberFormatOptions): string; | ||
(value: number | bigint, format?: string, options?: import("use-intl/core").NumberFormatOptions): string; | ||
}; | ||
relativeTime: { | ||
(date: number | Date, now?: import("use-intl/core").RelativeTimeFormatOptions["now"]): string; | ||
(date: number | Date, options?: import("use-intl/core").RelativeTimeFormatOptions): string; | ||
}; | ||
list: { | ||
<Value extends string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<import("react").ReactElement>; | ||
<Value extends string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, format?: string, options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<import("react").ReactElement>; | ||
}; | ||
dateTimeRange: { | ||
(start: Date | number, end: Date | number, options?: import("use-intl/core").DateTimeFormatOptions): string; | ||
(start: Date | number, end: Date | number, format?: string, options?: import("use-intl/core").DateTimeFormatOptions): string; | ||
}; | ||
}; | ||
declare const getFormatterCached: typeof getFormatterCachedImpl; | ||
export default getFormatterCached; |
@@ -18,2 +18,3 @@ import type { LinkProps } from 'next/link.js'; | ||
export declare function getSortedPathnames(pathnames: Array<string>): string[]; | ||
export declare function isPromise<Value>(value: Value | Promise<Value>): value is Promise<Value>; | ||
export {}; |
{ | ||
"name": "next-intl", | ||
"version": "4.0.0-beta-40d535a", | ||
"version": "4.0.0-beta-4106641", | ||
"sideEffects": false, | ||
@@ -115,3 +115,3 @@ "author": "Jan Amann <jan@amann.work>", | ||
"negotiator": "^1.0.0", | ||
"use-intl": "4.0.0-beta-40d535a" | ||
"use-intl": "4.0.0-beta-4106641" | ||
}, | ||
@@ -128,3 +128,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "036819e56a60031af2e0ef875916954dd6cc944d" | ||
"gitHead": "b8eaa58ecd2088f788d5f4b7510493ce7f850176" | ||
} |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
244805
1.3%205
1.49%4024
1.85%20
11.11%+ Added
- Removed
Updated