next-intl 2.3.0 → 2.3.4

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
@@ -11,30 +11,20 @@
11
11
 
12
12
  ![Gzipped size](https://badgen.net/bundlephobia/minzip/next-intl) ![Tree shaking supported](https://badgen.net/bundlephobia/tree-shaking/next-intl) [<img src="https://img.shields.io/npm/dw/next-intl.svg" />](https://www.npmjs.com/package/next-intl)
13
13
 
14
- This library complements the [internationalized routing](https://nextjs.org/docs/advanced-features/i18n-routing) capabilities of Next.js by managing translations and providing them to components.
15
-
16
14
  ## Features
17
15
 
18
- - 🌟 Messages use the **proven [ICU syntax](https://formatjs.io/docs/core-concepts/icu-syntax)** which covers interpolation, plurals, ordinal pluralization, label selection based on enums and rich text. I18n is an essential part of the user experience, therefore this library doesn't compromise on flexibility and never leaves you behind when you need to fine tune a translation.
19
- - 📅 Built-in **date, time and number formatting** provides all the necessary parts you need for localisation. You can use global formats for a consistent look & feel of your app and integrate them with translations.
20
- - 💡 A **hooks-only API** ensures that you can use the same API for `children` as well as for attributes which expect strings.
21
- - ⚔️ Based on **battle-tested** building blocks from [Format.JS](https://formatjs.io/) (used by `react-intl`) and modern browser APIs, this library is a thin wrapper around high-quality, lower-level APIs for i18n.
22
- - 🚀 By integrating with both **static as well as server side rendering** you always get the best possible performance from your app.
16
+ This library complements the [internationalized routing](https://nextjs.org/docs/advanced-features/i18n-routing) capabilities of Next.js by managing translations and providing them to components.
17
+
18
+ - 🌟 **Proven ICU syntax**: This covers interpolation, plurals, ordinal pluralization, label selection based on enums and rich text. I18n is an essential part of the user experience, therefore this library doesn't compromise on flexibility and never leaves you behind when you need to fine tune a translation.
19
+ - 📅 **Built-in date, time and number formatting**: You can use global formats for a consistent look & feel of your app and integrate them with translations.
20
+ - 💡 **Hooks-only API**: This ensures that you can use the same API for `children` as well as for attributes which expect strings.
21
+ - ⚔️ **Battle-tested building blocks**: This library is a minimal wrapper around built-in browser APIs and supplemental lower-level APIs from Format.JS.
22
+ - 🚀 **Fast**: By integrating with both static as well as server side rendering you always get the best possible performance from your app.
23
23
 
24
24
  ## What does it look like?
25
25
 
26
26
  This library is based on the premise that messages can be grouped by namespaces (typically a component name).
27
27
 
28
- ```js
29
- // en.json
30
- {
31
- "LatestFollower": {
32
- "latestFollower": "{username} started following you",
33
- "followBack": "Follow back"
34
- }
35
- }
36
- ```
37
-
38
28
  ```jsx
39
29
  // LatestFollower.js
40
30
  function LatestFollower({user}) {
@@ -49,9 +39,14 @@ function LatestFollower({user}) {
49
39
  }
50
40
  ```
51
41
 
52
- ## Docs
42
+ ```js
43
+ // en.json
44
+ {
45
+ "LatestFollower": {
46
+ "latestFollower": "{username} started following you",
47
+ "followBack": "Follow back"
48
+ }
49
+ }
50
+ ```
53
51
 
54
- - [Installation guide](./docs/installation.md)
55
- - [Usage guide](./docs/usage.md)
56
- - [FAQ](./docs/faq.md)
57
- - [Changelog](./CHANGELOG.md)
52
+ ### [ Read the docs](https://next-intl-docs.vercel.app/)
@@ -24,11 +24,18 @@ function _objectWithoutPropertiesLoose(source, excluded) {
24
24
  }
25
25
 
26
26
  function NextIntlProvider(_ref) {
27
+ var _useRouter;
28
+
27
29
  var locale = _ref.locale,
28
30
  rest = _objectWithoutPropertiesLoose(_ref, ["locale"]);
29
31
 
30
- var nextLocale = router.useRouter().locale;
31
- if (!locale && nextLocale) locale = nextLocale;
32
+ // The router can be undefined if used in a context outside
33
+ // of Next.js (e.g. unit tests, Storybook, ...)
34
+ var nextLocale = (_useRouter = router.useRouter()) == null ? void 0 : _useRouter.locale;
35
+
36
+ if (!locale && nextLocale) {
37
+ locale = nextLocale;
38
+ }
32
39
 
33
40
  if (!locale) {
34
41
  throw new Error( "Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`." );
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.cjs.development.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n const nextLocale = useRouter().locale;\n if (!locale && nextLocale) locale = nextLocale;\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","nextLocale","useRouter","Error","React","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;SAQwBA;MAAkBC,cAAAA;MAAWC;;AACnD,MAAMC,UAAU,GAAGC,gBAAS,GAAGH,MAA/B;AACA,MAAI,CAACA,MAAD,IAAWE,UAAf,EAA2BF,MAAM,GAAGE,UAAT;;AAE3B,MAAI,CAACF,MAAL,EAAa;AACX,UAAM,IAAII,KAAJ,EAEA,+IADJ,CADI,CAAN;AAKD;;AAED,SAAOC,mBAAA,CAACC,oBAAD;AAAcN,IAAAA,MAAM,EAAEA;KAAYC,KAAlC,CAAP;AACD;;;;;;;;;;;;"}
1
+ {"version":3,"file":"next-intl.cjs.development.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n const nextLocale = useRouter()?.locale;\n\n if (!locale && nextLocale) {\n locale = nextLocale;\n }\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","nextLocale","useRouter","Error","React","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;SAQwBA;;;MAAkBC,cAAAA;MAAWC;;AACnD;AACA;AACA,MAAMC,UAAU,iBAAGC,gBAAS,EAAZ,qBAAG,WAAaH,MAAhC;;AAEA,MAAI,CAACA,MAAD,IAAWE,UAAf,EAA2B;AACzBF,IAAAA,MAAM,GAAGE,UAAT;AACD;;AAED,MAAI,CAACF,MAAL,EAAa;AACX,UAAM,IAAII,KAAJ,EAEA,+IADJ,CADI,CAAN;AAKD;;AAED,SAAOC,mBAAA,CAACC,oBAAD;AAAcN,IAAAA,MAAM,EAAEA;KAAYC,KAAlC,CAAP;AACD;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("next/router"),t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("use-intl");Object.keys(n).forEach((function(e){"default"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})})),exports.NextIntlProvider=function(e){var o=e.locale,u=function(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r.indexOf(t=u[n])>=0||(o[t]=e[t]);return o}(e,["locale"]),l=r.useRouter().locale;if(!o&&l&&(o=l),!o)throw new Error(void 0);return t.createElement(n.IntlProvider,Object.assign({locale:o},u))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("next/router"),t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("use-intl");Object.keys(n).forEach((function(e){"default"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})})),exports.NextIntlProvider=function(e){var o,u=e.locale,l=function(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r.indexOf(t=u[n])>=0||(o[t]=e[t]);return o}(e,["locale"]),i=null==(o=r.useRouter())?void 0:o.locale;if(!u&&i&&(u=i),!u)throw new Error(void 0);return t.createElement(n.IntlProvider,Object.assign({locale:u},l))};
2
2
  //# sourceMappingURL=next-intl.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n const nextLocale = useRouter().locale;\n if (!locale && nextLocale) locale = nextLocale;\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["locale","rest","nextLocale","useRouter","Error","undefined","React","IntlProvider"],"mappings":"2WAQ0CA,IAAAA,OAAWC,mJAC7CC,EAAaC,cAAYH,WAC1BA,GAAUE,IAAYF,EAASE,IAE/BF,QACG,IAAII,WAGJC,UAIDC,gBAACC,8BAAaP,OAAQA,GAAYC"}
1
+ {"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n const nextLocale = useRouter()?.locale;\n\n if (!locale && nextLocale) {\n locale = nextLocale;\n }\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["locale","rest","nextLocale","useRouter","_useRouter","Error","undefined","React","IntlProvider"],"mappings":"6WAQ0CA,IAAAA,OAAWC,mJAG7CC,WAAaC,sBAAAC,EAAaJ,WAE3BA,GAAUE,IACbF,EAASE,IAGNF,QACG,IAAIK,WAGJC,UAIDC,gBAACC,8BAAaR,OAAQA,GAAYC"}
@@ -19,11 +19,18 @@ function _objectWithoutPropertiesLoose(source, excluded) {
19
19
  }
20
20
 
21
21
  function NextIntlProvider(_ref) {
22
+ var _useRouter;
23
+
22
24
  var locale = _ref.locale,
23
25
  rest = _objectWithoutPropertiesLoose(_ref, ["locale"]);
24
26
 
25
- var nextLocale = useRouter().locale;
26
- if (!locale && nextLocale) locale = nextLocale;
27
+ // The router can be undefined if used in a context outside
28
+ // of Next.js (e.g. unit tests, Storybook, ...)
29
+ var nextLocale = (_useRouter = useRouter()) == null ? void 0 : _useRouter.locale;
30
+
31
+ if (!locale && nextLocale) {
32
+ locale = nextLocale;
33
+ }
27
34
 
28
35
  if (!locale) {
29
36
  throw new Error(process.env.NODE_ENV !== "production" ? "Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`." : undefined);
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n const nextLocale = useRouter().locale;\n if (!locale && nextLocale) locale = nextLocale;\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","nextLocale","useRouter","Error","undefined","React","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;SAQwBA;MAAkBC,cAAAA;MAAWC;;AACnD,MAAMC,UAAU,GAAGC,SAAS,GAAGH,MAA/B;AACA,MAAI,CAACA,MAAD,IAAWE,UAAf,EAA2BF,MAAM,GAAGE,UAAT;;AAE3B,MAAI,CAACF,MAAL,EAAa;AACX,UAAM,IAAII,KAAJ,CACJ,wCACI,+IADJ,GAEIC,SAHA,CAAN;AAKD;;AAED,SAAOC,mBAAA,CAACC,YAAD;AAAcP,IAAAA,MAAM,EAAEA;KAAYC,KAAlC,CAAP;AACD;;;;"}
1
+ {"version":3,"file":"next-intl.esm.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["import {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n const nextLocale = useRouter()?.locale;\n\n if (!locale && nextLocale) {\n locale = nextLocale;\n }\n\n if (!locale) {\n throw new Error(\n __DEV__\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","nextLocale","useRouter","Error","undefined","React","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;SAQwBA;;;MAAkBC,cAAAA;MAAWC;;AACnD;AACA;AACA,MAAMC,UAAU,iBAAGC,SAAS,EAAZ,qBAAG,WAAaH,MAAhC;;AAEA,MAAI,CAACA,MAAD,IAAWE,UAAf,EAA2B;AACzBF,IAAAA,MAAM,GAAGE,UAAT;AACD;;AAED,MAAI,CAACF,MAAL,EAAa;AACX,UAAM,IAAII,KAAJ,CACJ,wCACI,+IADJ,GAEIC,SAHA,CAAN;AAKD;;AAED,SAAOC,mBAAA,CAACC,YAAD;AAAcP,IAAAA,MAAM,EAAEA;KAAYC,KAAlC,CAAP;AACD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "2.3.0",
3
+ "version": "2.3.4",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.me>",
6
6
  "description": "A minimal, but complete solution for managing translations, date and number formatting in Next.js apps.",
@@ -37,7 +37,7 @@
37
37
  "next.js"
38
38
  ],
39
39
  "dependencies": {
40
- "use-intl": "^2.3.0"
40
+ "use-intl": "^2.3.4"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=10"
60
60
  },
61
- "gitHead": "1571b78688fa2735011b2170e7811e83fd574204"
61
+ "gitHead": "674e4837d625785d1c4242d742f811b7383d8f89"
62
62
  }
@@ -7,8 +7,13 @@ type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {
7
7
  };
8
8
 
9
9
  export default function NextIntlProvider({locale, ...rest}: Props) {
10
- const nextLocale = useRouter().locale;
11
- if (!locale && nextLocale) locale = nextLocale;
10
+ // The router can be undefined if used in a context outside
11
+ // of Next.js (e.g. unit tests, Storybook, ...)
12
+ const nextLocale = useRouter()?.locale;
13
+
14
+ if (!locale && nextLocale) {
15
+ locale = nextLocale;
16
+ }
12
17
 
13
18
  if (!locale) {
14
19
  throw new Error(