use-intl 3.0.0-rc.6 → 3.0.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 +12 -17
- package/dist/development/_IntlProvider.js +31 -5
- package/dist/esm/_IntlProvider.js +1 -1
- package/dist/production/_IntlProvider.js +1 -1
- package/dist/types/src/react/IntlProvider.d.ts +1 -1
- package/dist/types/test/react/IntlProvider.test.d.ts +1 -0
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# 🌐 use-intl
|
|
2
2
|
|
|
3
|
-
  [<img src="https://img.shields.io/npm/dw/use-intl.svg" />](https://www.npmjs.com/package/use-intl)
|
|
4
|
-
|
|
5
3
|
> Internationalization for React that gets out of your way.
|
|
6
4
|
|
|
7
5
|
## Features
|
|
8
6
|
|
|
9
7
|
Internationalization is an essential part of the user experience. use-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.
|
|
10
8
|
|
|
11
|
-
- 🌟 **ICU message syntax**: Localize your messages with interpolation,
|
|
9
|
+
- 🌟 **ICU message syntax**: Localize your messages with interpolation, cardinal & ordinal plurals, enum-based label selection and rich text.
|
|
12
10
|
- 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
|
|
13
11
|
- ✅ **Type-safe**: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
|
|
14
12
|
- 💡 **Hooks-only API**: Learn a single API that can be used across your code base to turn translations into plain strings or rich text.
|
|
@@ -19,19 +17,17 @@ Internationalization is an essential part of the user experience. use-intl gives
|
|
|
19
17
|
This library is based on the premise that messages can be grouped by namespaces (typically a component name).
|
|
20
18
|
|
|
21
19
|
```jsx
|
|
22
|
-
//
|
|
23
|
-
import {useTranslations
|
|
20
|
+
// UserProfile.tsx
|
|
21
|
+
import {useTranslations} from 'next-intl';
|
|
24
22
|
|
|
25
|
-
function
|
|
26
|
-
const t = useTranslations('
|
|
27
|
-
const format = useFormatter();
|
|
23
|
+
export default function UserProfile({user}) {
|
|
24
|
+
const t = useTranslations('UserProfile');
|
|
28
25
|
|
|
29
26
|
return (
|
|
30
27
|
<section>
|
|
31
|
-
<
|
|
32
|
-
<p>{t('
|
|
33
|
-
<p>{t('
|
|
34
|
-
<Image alt={t('portrait', {username: user.name})} src={user.portrait} />
|
|
28
|
+
<h1>{t('title', {firstName: user.firstName})}</h1>
|
|
29
|
+
<p>{t('membership', {memberSince: user.memberSince})}</p>
|
|
30
|
+
<p>{t('followers', {count: user.numFollowers})}</p>
|
|
35
31
|
</section>
|
|
36
32
|
);
|
|
37
33
|
}
|
|
@@ -40,15 +36,14 @@ function UserDetails({user}) {
|
|
|
40
36
|
```js
|
|
41
37
|
// en.json
|
|
42
38
|
{
|
|
43
|
-
"
|
|
44
|
-
"title": "
|
|
39
|
+
"UserProfile": {
|
|
40
|
+
"title": "{username}'s profile",
|
|
41
|
+
"membership": "Member since {memberSince, date, short}",
|
|
45
42
|
"followers": "{count, plural, ↵
|
|
46
43
|
=0 {No followers yet} ↵
|
|
47
44
|
=1 {One follower} ↵
|
|
48
45
|
other {# followers} ↵
|
|
49
|
-
}"
|
|
50
|
-
"lastSeen": "Last seen {time}",
|
|
51
|
-
"portrait": "Portrait of {username}"
|
|
46
|
+
}"
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
```
|
|
@@ -13,14 +13,40 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
13
13
|
function IntlProvider(_ref) {
|
|
14
14
|
let {
|
|
15
15
|
children,
|
|
16
|
-
|
|
16
|
+
defaultTranslationValues,
|
|
17
|
+
formats,
|
|
18
|
+
getMessageFallback,
|
|
19
|
+
locale,
|
|
20
|
+
messages,
|
|
21
|
+
now,
|
|
22
|
+
onError,
|
|
23
|
+
timeZone
|
|
17
24
|
} = _ref;
|
|
18
25
|
const [messageFormatCache] = React.useState(() => new Map());
|
|
26
|
+
|
|
27
|
+
// Memoizing this value helps to avoid triggering a re-render of all
|
|
28
|
+
// context consumers in case the configuration didn't change. However,
|
|
29
|
+
// if some of the non-primitive values change, a re-render will still
|
|
30
|
+
// be triggered. Note that there's no need to put `memo` on `IntlProvider`
|
|
31
|
+
// itself, because the `children` typically change on every render.
|
|
32
|
+
// There's some burden on the consumer side if it's important to reduce
|
|
33
|
+
// re-renders, put that's how React works.
|
|
34
|
+
// See: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations
|
|
35
|
+
const value = React.useMemo(() => ({
|
|
36
|
+
...initializeConfig.initializeConfig({
|
|
37
|
+
locale,
|
|
38
|
+
defaultTranslationValues,
|
|
39
|
+
formats,
|
|
40
|
+
getMessageFallback,
|
|
41
|
+
messages,
|
|
42
|
+
now,
|
|
43
|
+
onError,
|
|
44
|
+
timeZone
|
|
45
|
+
}),
|
|
46
|
+
messageFormatCache
|
|
47
|
+
}), [defaultTranslationValues, formats, getMessageFallback, locale, messageFormatCache, messages, now, onError, timeZone]);
|
|
19
48
|
return /*#__PURE__*/React__default.default.createElement(IntlContext.IntlContext.Provider, {
|
|
20
|
-
value:
|
|
21
|
-
...initializeConfig.initializeConfig(config),
|
|
22
|
-
messageFormatCache
|
|
23
|
-
}
|
|
49
|
+
value: value
|
|
24
50
|
}, children);
|
|
25
51
|
}
|
|
26
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-29e7ba4c.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-29e7ba4c.js"),a=require("./IntlContext-381f3ce4.js");function r(e){return e&&e.__esModule?e:{default:e}}var n=r(e);exports.IntlProvider=function(r){let{children:o,defaultTranslationValues:s,formats:l,getMessageFallback:i,locale:u,messages:c,now:f,onError:d,timeZone:m}=r;const[g]=e.useState((()=>new Map)),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:s,formats:l,getMessageFallback:i,messages:c,now:f,onError:d,timeZone:m}),messageFormatCache:g})),[s,l,i,u,g,c,f,d,m]);return n.default.createElement(a.IntlContext.Provider,{value:v},o)};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-984a566d.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-984a566d.js"),a=require("./IntlContext-381f3ce4.js");function r(e){return e&&e.__esModule?e:{default:e}}var n=r(e);exports.IntlProvider=function(r){let{children:o,defaultTranslationValues:s,formats:l,getMessageFallback:i,locale:u,messages:c,now:f,onError:d,timeZone:m}=r;const[g]=e.useState((()=>new Map)),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:s,formats:l,getMessageFallback:i,messages:c,now:f,onError:d,timeZone:m}),messageFormatCache:g})),[s,l,i,u,g,c,f,d,m]);return n.default.createElement(a.IntlContext.Provider,{value:v},o)};
|
|
@@ -3,5 +3,5 @@ import IntlConfig from '../core/IntlConfig';
|
|
|
3
3
|
type Props = IntlConfig & {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
};
|
|
6
|
-
export default function IntlProvider({ children,
|
|
6
|
+
export default function IntlProvider({ children, defaultTranslationValues, formats, getMessageFallback, locale, messages, now, onError, timeZone }: Props): React.JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "Minimal, but complete solution for managing internationalization in React apps.",
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/amannn/next-intl/tree/main/packages/use-intl"
|
|
12
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rm -rf dist && rollup -c",
|
|
15
|
+
"test": "TZ=Europe/Berlin vitest",
|
|
16
|
+
"lint": "eslint src test && tsc --noEmit",
|
|
17
|
+
"prepublishOnly": "CI=true turbo test && turbo lint && turbo build",
|
|
18
|
+
"size": "size-limit"
|
|
19
|
+
},
|
|
13
20
|
"main": "./dist/index.js",
|
|
14
21
|
"module": "dist/esm/index.js",
|
|
15
22
|
"typings": "./dist/types/src/index.d.ts",
|
|
@@ -73,19 +80,14 @@
|
|
|
73
80
|
"react-dom": "^18.2.0",
|
|
74
81
|
"rollup": "^3.28.1",
|
|
75
82
|
"size-limit": "^8.2.6",
|
|
76
|
-
"typescript": "^5.
|
|
83
|
+
"typescript": "^5.2.2",
|
|
77
84
|
"vitest": "^0.32.2"
|
|
78
85
|
},
|
|
79
86
|
"size-limit": [
|
|
80
87
|
{
|
|
81
88
|
"path": "dist/production/index.js",
|
|
82
|
-
"limit": "12.
|
|
89
|
+
"limit": "12.355 kB"
|
|
83
90
|
}
|
|
84
91
|
],
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
"test": "TZ=Europe/Berlin vitest",
|
|
88
|
-
"lint": "eslint src test && tsc --noEmit",
|
|
89
|
-
"size": "size-limit"
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
+
"gitHead": "b3297ca0514b9393f1ba091883c47e79a77be130"
|
|
93
|
+
}
|