next-intl 3.11.0-beta.2 → 3.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  ## Features
23
23
 
24
- Internationalization is an essential part of the user experience. `next-intl` gives you everything you need to get language subtleties right and has always got your back whenever you need to fine-tune a translation.
24
+ Internationalization (i18n) is an essential part of the user experience, therefore `next-intl` gives you all the parts you need to get language nuances right.
25
25
 
26
26
  - 🌟 **ICU message syntax**: Localize your messages with interpolation, cardinal & ordinal plurals, enum-based label selection and rich text.
27
27
  - 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
@@ -32,8 +32,6 @@ Internationalization is an essential part of the user experience. `next-intl` gi
32
32
 
33
33
  ## What does it look like?
34
34
 
35
- This library is based on the premise that messages can be grouped by namespaces (typically a component name).
36
-
37
35
  ```jsx
38
36
  // UserProfile.tsx
39
37
  import {useTranslations} from 'next-intl';
@@ -64,10 +64,12 @@ function createMiddleware(config) {
64
64
  }
65
65
  }
66
66
  if (redirectDomain) {
67
- var _request$headers$get;
68
- urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
69
- urlObj.port = '';
70
67
  urlObj.host = redirectDomain;
68
+ if (request.headers.get('x-forwarded-host')) {
69
+ var _request$headers$get, _request$headers$get2;
70
+ urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
71
+ urlObj.port = (_request$headers$get2 = request.headers.get('x-forwarded-port')) !== null && _request$headers$get2 !== void 0 ? _request$headers$get2 : '';
72
+ }
71
73
  }
72
74
  if (request.nextUrl.basePath) {
73
75
  urlObj.pathname = utils.applyBasePath(urlObj.pathname, request.nextUrl.basePath);
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,COOKIE_SAME_SITE as a,COOKIE_MAX_AGE as n,HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as l}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getPathnameLocale as d,getInternalTemplate as f,formatTemplatePathname as u,getPathWithSearch as m,getBestMatchingDomain as h,applyBasePath as v}from"./utils.js";function p(p){const x=function(e){var t,a,n;return{...e,alternateLinks:null===(t=e.alternateLinks)||void 0===t||t,localePrefix:null!==(a=e.localePrefix)&&void 0!==a?a:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(p);return function(p){var P,U;const L=decodeURI(p.nextUrl.pathname),{domain:g,locale:k}=s(x,p.headers,p.cookies,L),w=x.localeDetection&&(null===(P=p.cookies.get(t))||void 0===P?void 0:P.value)!==k,b=g?g.defaultLocale===k:k===x.defaultLocale,j=(null===(U=x.domains)||void 0===U?void 0:U.filter((e=>i(k,e))))||[],y=null!=x.domains&&!g;function D(t){const a=new URL(t,p.url);return p.nextUrl.basePath&&(a.pathname=v(a.pathname,p.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(p.headers);return e.set(o,k),{request:{headers:e}}}())}function R(t,a){const n=new URL(t,p.url);if(j.length>0&&!a){const e=h(g,k,j);e&&(a=e.domain,e.defaultLocale===k&&"as-needed"===x.localePrefix&&n.pathname.startsWith("/".concat(k))&&(n.pathname=c(n.pathname,x.locales)))}var o;a&&(n.protocol=null!==(o=p.headers.get("x-forwarded-proto"))&&void 0!==o?o:p.nextUrl.protocol,n.port="",n.host=a);return p.nextUrl.basePath&&(n.pathname=v(n.pathname,p.nextUrl.basePath)),e.redirect(n.toString())}const q=c(L,x.locales),A=d(L,x.locales),H=null!=A;let S,z,I=L;if(x.pathnames){let e;if([e,z]=f(x.pathnames,q,k),z){const t=x.pathnames[z],a="string"==typeof t?t:t[k];if(l(a,q))I=u(q,a,z,A);else{let n;n=e?"string"==typeof t?t:t[e]:z;const o=!H&&b||"never"===x.localePrefix?void 0:k;S=R(m(u(q,n,a,o),p.nextUrl.search))}}}if(!S)if("/"===I){const e=m("/".concat(k),p.nextUrl.search);S="never"===x.localePrefix||b&&"as-needed"===x.localePrefix?D(e):R(e)}else{const e=m(I,p.nextUrl.search);if(H){const t=m(q,p.nextUrl.search);if("never"===x.localePrefix)S=R(t);else if(A===k)if(b&&"as-needed"===x.localePrefix)S=R(t);else if(x.domains){const a=h(g,A,j);S=(null==g?void 0:g.domain)===(null==a?void 0:a.domain)||y?D(e):R(t,null==a?void 0:a.domain)}else S=D(e);else S=R("/".concat(k).concat(t))}else S="never"===x.localePrefix||b&&("as-needed"===x.localePrefix||x.domains)?D("/".concat(k).concat(e)):R("/".concat(k).concat(e))}var V;(w&&S.cookies.set(t,k,{path:p.nextUrl.basePath||void 0,sameSite:a,maxAge:n}),"never"!==x.localePrefix&&x.alternateLinks&&x.locales.length>1)&&S.headers.set("Link",r({config:x,localizedPathnames:null!=z?null===(V=x.pathnames)||void 0===V?void 0:V[z]:void 0,request:p,resolvedLocale:k}));return S}}export{p as default};
1
+ import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,COOKIE_SAME_SITE as a,COOKIE_MAX_AGE as o,HEADER_LOCALE_NAME as n}from"../shared/constants.js";import{matchesPathname as l}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getPathnameLocale as d,getInternalTemplate as f,formatTemplatePathname as u,getPathWithSearch as h,getBestMatchingDomain as m,applyBasePath as v}from"./utils.js";function x(x){const p=function(e){var t,a,o;return{...e,alternateLinks:null===(t=e.alternateLinks)||void 0===t||t,localePrefix:null!==(a=e.localePrefix)&&void 0!==a?a:"always",localeDetection:null===(o=e.localeDetection)||void 0===o||o}}(x);return function(x){var P,U;const g=decodeURI(x.nextUrl.pathname),{domain:L,locale:k}=s(p,x.headers,x.cookies,g),w=p.localeDetection&&(null===(P=x.cookies.get(t))||void 0===P?void 0:P.value)!==k,b=L?L.defaultLocale===k:k===p.defaultLocale,j=(null===(U=p.domains)||void 0===U?void 0:U.filter((e=>i(k,e))))||[],y=null!=p.domains&&!L;function D(t){const a=new URL(t,x.url);return x.nextUrl.basePath&&(a.pathname=v(a.pathname,x.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(x.headers);return e.set(n,k),{request:{headers:e}}}())}function R(t,a){const o=new URL(t,x.url);if(j.length>0&&!a){const e=m(L,k,j);e&&(a=e.domain,e.defaultLocale===k&&"as-needed"===p.localePrefix&&o.pathname.startsWith("/".concat(k))&&(o.pathname=c(o.pathname,p.locales)))}var n,l;a&&(o.host=a,x.headers.get("x-forwarded-host")&&(o.protocol=null!==(n=x.headers.get("x-forwarded-proto"))&&void 0!==n?n:x.nextUrl.protocol,o.port=null!==(l=x.headers.get("x-forwarded-port"))&&void 0!==l?l:""));return x.nextUrl.basePath&&(o.pathname=v(o.pathname,x.nextUrl.basePath)),e.redirect(o.toString())}const q=c(g,p.locales),A=d(g,p.locales),H=null!=A;let S,z,I=g;if(p.pathnames){let e;if([e,z]=f(p.pathnames,q,k),z){const t=p.pathnames[z],a="string"==typeof t?t:t[k];if(l(a,q))I=u(q,a,z,A);else{let o;o=e?"string"==typeof t?t:t[e]:z;const n=!H&&b||"never"===p.localePrefix?void 0:k;S=R(h(u(q,o,a,n),x.nextUrl.search))}}}if(!S)if("/"===I){const e=h("/".concat(k),x.nextUrl.search);S="never"===p.localePrefix||b&&"as-needed"===p.localePrefix?D(e):R(e)}else{const e=h(I,x.nextUrl.search);if(H){const t=h(q,x.nextUrl.search);if("never"===p.localePrefix)S=R(t);else if(A===k)if(b&&"as-needed"===p.localePrefix)S=R(t);else if(p.domains){const a=m(L,A,j);S=(null==L?void 0:L.domain)===(null==a?void 0:a.domain)||y?D(e):R(t,null==a?void 0:a.domain)}else S=D(e);else S=R("/".concat(k).concat(t))}else S="never"===p.localePrefix||b&&("as-needed"===p.localePrefix||p.domains)?D("/".concat(k).concat(e)):R("/".concat(k).concat(e))}var V;(w&&S.cookies.set(t,k,{path:x.nextUrl.basePath||void 0,sameSite:a,maxAge:o}),"never"!==p.localePrefix&&p.alternateLinks&&p.locales.length>1)&&S.headers.set("Link",r({config:p,localizedPathnames:null!=z?null===(V=p.pathnames)||void 0===V?void 0:V[z]:void 0,request:x,resolvedLocale:k}));return S}}export{x as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const s=function(e){var a,t,n;return{...e,alternateLinks:null===(a=e.alternateLinks)||void 0===a||a,localePrefix:null!==(t=e.localePrefix)&&void 0!==t?t:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(r);return function(r){var i,c;const d=decodeURI(r.nextUrl.pathname),{domain:h,locale:u}=l.default(s,r.headers,r.cookies,d),f=s.localeDetection&&(null===(i=r.cookies.get(a.COOKIE_LOCALE_NAME))||void 0===i?void 0:i.value)!==u,m=h?h.defaultLocale===u:u===s.defaultLocale,p=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=s.domains&&!h;function P(t){const n=new URL(t,r.url);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.rewrite(n,function(){const e=new Headers(r.headers);return e.set(a.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(p.length>0&&!t){const e=o.getBestMatchingDomain(h,u,p);e&&(t=e.domain,e.defaultLocale===u&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(u))&&(n.pathname=o.getNormalizedPathname(n.pathname,s.locales)))}var l;t&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port="",n.host=t);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const g=o.getNormalizedPathname(d,s.locales),L=o.getPathnameLocale(d,s.locales),E=null!=L;let U,O,A=d;if(s.pathnames){let e;if([e,O]=o.getInternalTemplate(s.pathnames,g,u),O){const a=s.pathnames[O],n="string"==typeof a?a:a[u];if(t.matchesPathname(n,g))A=o.formatTemplatePathname(g,n,O,L);else{let t;t=e?"string"==typeof a?a:a[e]:O;const l=!E&&m||"never"===s.localePrefix?void 0:u;U=x(o.getPathWithSearch(o.formatTemplatePathname(g,t,n,l),r.nextUrl.search))}}}if(!U)if("/"===A){const e=o.getPathWithSearch("/".concat(u),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?P(e):x(e)}else{const e=o.getPathWithSearch(A,r.nextUrl.search);if(E){const a=o.getPathWithSearch(g,r.nextUrl.search);if("never"===s.localePrefix)U=x(a);else if(L===u)if(m&&"as-needed"===s.localePrefix)U=x(a);else if(s.domains){const t=o.getBestMatchingDomain(h,L,p);U=(null==h?void 0:h.domain)===(null==t?void 0:t.domain)||v?P(e):x(a,null==t?void 0:t.domain)}else U=P(e);else U=x("/".concat(u).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?P("/".concat(u).concat(e)):x("/".concat(u).concat(e))}var _;(f&&U.cookies.set(a.COOKIE_LOCALE_NAME,u,{path:r.nextUrl.basePath||void 0,sameSite:a.COOKIE_SAME_SITE,maxAge:a.COOKIE_MAX_AGE}),"never"!==s.localePrefix&&s.alternateLinks&&s.locales.length>1)&&U.headers.set("Link",n.default({config:s,localizedPathnames:null!=O?null===(_=s.pathnames)||void 0===_?void 0:_[O]:void 0,request:r,resolvedLocale:u}));return U}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const s=function(e){var a,t,n;return{...e,alternateLinks:null===(a=e.alternateLinks)||void 0===a||a,localePrefix:null!==(t=e.localePrefix)&&void 0!==t?t:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(r);return function(r){var i,c;const d=decodeURI(r.nextUrl.pathname),{domain:h,locale:u}=l.default(s,r.headers,r.cookies,d),f=s.localeDetection&&(null===(i=r.cookies.get(a.COOKIE_LOCALE_NAME))||void 0===i?void 0:i.value)!==u,m=h?h.defaultLocale===u:u===s.defaultLocale,p=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=s.domains&&!h;function x(t){const n=new URL(t,r.url);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.rewrite(n,function(){const e=new Headers(r.headers);return e.set(a.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function P(a,t){const n=new URL(a,r.url);if(p.length>0&&!t){const e=o.getBestMatchingDomain(h,u,p);e&&(t=e.domain,e.defaultLocale===u&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(u))&&(n.pathname=o.getNormalizedPathname(n.pathname,s.locales)))}var l,i;t&&(n.host=t,r.headers.get("x-forwarded-host")&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port=null!==(i=r.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const g=o.getNormalizedPathname(d,s.locales),L=o.getPathnameLocale(d,s.locales),E=null!=L;let U,O,A=d;if(s.pathnames){let e;if([e,O]=o.getInternalTemplate(s.pathnames,g,u),O){const a=s.pathnames[O],n="string"==typeof a?a:a[u];if(t.matchesPathname(n,g))A=o.formatTemplatePathname(g,n,O,L);else{let t;t=e?"string"==typeof a?a:a[e]:O;const l=!E&&m||"never"===s.localePrefix?void 0:u;U=P(o.getPathWithSearch(o.formatTemplatePathname(g,t,n,l),r.nextUrl.search))}}}if(!U)if("/"===A){const e=o.getPathWithSearch("/".concat(u),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?x(e):P(e)}else{const e=o.getPathWithSearch(A,r.nextUrl.search);if(E){const a=o.getPathWithSearch(g,r.nextUrl.search);if("never"===s.localePrefix)U=P(a);else if(L===u)if(m&&"as-needed"===s.localePrefix)U=P(a);else if(s.domains){const t=o.getBestMatchingDomain(h,L,p);U=(null==h?void 0:h.domain)===(null==t?void 0:t.domain)||v?x(e):P(a,null==t?void 0:t.domain)}else U=x(e);else U=P("/".concat(u).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?x("/".concat(u).concat(e)):P("/".concat(u).concat(e))}var _;(f&&U.cookies.set(a.COOKIE_LOCALE_NAME,u,{path:r.nextUrl.basePath||void 0,sameSite:a.COOKIE_SAME_SITE,maxAge:a.COOKIE_MAX_AGE}),"never"!==s.localePrefix&&s.alternateLinks&&s.locales.length>1)&&U.headers.set("Link",n.default({config:s,localizedPathnames:null!=O?null===(_=s.pathnames)||void 0===_?void 0:_[O]:void 0,request:r,resolvedLocale:u}));return U}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.11.0-beta.2",
3
+ "version": "3.11.1",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -16,6 +16,16 @@
16
16
  "type": "git",
17
17
  "url": "https://github.com/amannn/next-intl"
18
18
  },
19
+ "scripts": {
20
+ "build": "rm -rf dist && rollup -c",
21
+ "test": "TZ=Europe/Berlin vitest",
22
+ "lint": "pnpm run lint:source && pnpm run lint:package",
23
+ "lint:source": "eslint src test && tsc --noEmit",
24
+ "lint:package": "publint && attw --pack",
25
+ "prepublishOnly": "CI=true turbo test && turbo lint && turbo build && cp ../../README.md .",
26
+ "postpublish": "git checkout . && rm ./README.md",
27
+ "size": "size-limit"
28
+ },
19
29
  "main": "./dist/index.react-client.js",
20
30
  "module": "./dist/esm/index.react-client.js",
21
31
  "typings": "./dist/types/src/index.react-client.d.ts",
@@ -72,7 +82,7 @@
72
82
  "dependencies": {
73
83
  "@formatjs/intl-localematcher": "^0.2.32",
74
84
  "negotiator": "^0.6.3",
75
- "use-intl": "^3.10.0"
85
+ "use-intl": "^3.11.1"
76
86
  },
77
87
  "peerDependencies": {
78
88
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -131,12 +141,5 @@
131
141
  "limit": "5.95 KB"
132
142
  }
133
143
  ],
134
- "scripts": {
135
- "build": "rm -rf dist && rollup -c",
136
- "test": "TZ=Europe/Berlin vitest",
137
- "lint": "pnpm run lint:source && pnpm run lint:package",
138
- "lint:source": "eslint src test && tsc --noEmit",
139
- "lint:package": "publint && attw --pack",
140
- "size": "size-limit"
141
- }
142
- }
144
+ "gitHead": "78f88d1493eb796498b7fb2c986536ac49cffda0"
145
+ }