use-intl
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

🌐 use-intl

Internationalization (i18n) for React

Features

Internationalization (i18n) is an essential part of the user experience, therefore use-intl gives you all the parts you need to get language nuances right.

  • 🌟 ICU message syntax: Localize your messages with interpolation, cardinal & ordinal plurals, enum-based label selection and rich text.
  • 📅 Dates, times & numbers: Apply appropriate formatting without worrying about server/client differences like time zones.
  • Type-safe: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
  • 💡 Hooks-based API: Learn a single API that can be used across your code base to turn translations into plain strings or rich text.
  • ⚔️ Standards-based: Use the best parts of built-in JavaScript APIs and supplemental lower-level APIs from Format.JS.

What does it look like?

// UserProfile.tsx
import {useTranslations} from 'use-intl';

export default function UserProfile({user}) {
  const t = useTranslations('UserProfile');

  return (
    <section>
      <h1>{t('title', {firstName: user.firstName})}</h1>
      <p>{t('membership', {memberSince: user.memberSince})}</p>
      <p>{t('followers', {count: user.numFollowers})}</p>
    </section>
  );
}
// en.json
{
  "UserProfile": {
    "title": "{firstName}'s profile",
    "membership": "Member since {memberSince, date, short}",
    "followers": "{count, plural, ↵
                    =0 {No followers yet} 
                    =1 {One follower} 
                    other {# followers} 
                  }"
  }
}

Installation

  1. npm install use-intl
  2. Add the provider
  3. Use internationalization in components
import {IntlProvider, useTranslations} from 'use-intl';

// You can get the messages from anywhere you like. You can also
// fetch them from within a component and then render the provider
// along with your app once you have the messages.
const messages = {
  App: {
    hello: 'Hello {firstName}!'
  }
};

function Root() {
  return (
    <IntlProvider messages={messages} locale="en">
      <App user={{firstName: 'Jane'}} />
    </IntlProvider>
  );
}

function App({user}) {
  const t = useTranslations('App');
  return <h1>{t('hello', {firstName: user.firstName})}</h1>;
}

Have a look at the minimal setup example to explore a working app.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.13.4777test
3.6.0-alpha.10next
4.0.0-beta-dea867b
107v4-beta
0.0.0-canary-09b34ea
42canary
4.0.0-beta-7b755e9
2v4
0.0.0-canary-49646971prerelease
4.1.0
0latest

Version History

VersionDownloads (Last 7 Days)Published
4.1.0
0
0.0.0-canary-09b34ea
42
4.0.3
15,566
0.0.0-canary-58b4a57
309
4.0.2
104,003
4.0.1
544
0.0.0-canary-fdaddc5
1
4.0.0
277
4.0.0-beta-dea867b
107
4.0.0-beta-021e874
4
4.0.0-beta-4106641
4
3.26.5
136,701
4.0.0-beta-1a5e0ec
4
4.0.0-beta-22cf1cd
2
4.0.0-beta-ca68f02
0
3.26.4
6,259
0.0.0-canary-84fe6d0
0
4.0.0-beta-ca3fcd5
7
4.0.0-beta-c4c5986
4
4.0.0-beta-9e73cbe
0
4.0.0-beta-bae1131
2
4.0.0-beta-77949ef
0
4.0.0-beta-40d535a
2
4.0.0-beta-c40c5c9
0
4.0.0-beta-67507cc
3
4.0.0-beta-5b218d4
4
0.0.0-canary-255c5c2
4
4.0.0-beta-5ec7f45
2
4.0.0-beta-f511797
16
4.0.0-beta-32fc4e3
0
4.0.0-beta-f10dbba
4
4.0.0-beta-ddd5ae5
37
3.26.3
64,872
4.0.0-beta-0825f08
3
4.0.0-beta-7e7011d
0
3.26.2
8,676
3.26.1
4,630
3.26.0
4,504
4.0.0-beta-8f37883
1
4.0.0-beta-db95243
65
3.25.3
6,088
0.0.0-canary-b73586f
1
3.25.2
215
0.0.0-canary-a205821
1
4.0.0-beta-8cce53e
2
4.0.0-beta-c323050
1
4.0.0-beta-18156c4
8
4.0.0-beta-7b755e9
2
4.0.0-beta-5a7f7be
1
4.0.0-beta-c8eb4ad
1
4.0.0-beta-9ea117c
2
4.0.0-beta-00a79d4
1
3.25.1
9,009
3.25.0
3,916
3.24.0
3,738
3.23.5
3,785
3.23.4
12
3.23.3
35
3.23.2
4,073
3.23.1
623
3.23.0
1
3.22.0
580
0.0.0-canary-7b3a9a3
12
0.0.0-canary-0b8e3a5
1
0.0.0-canary-0ea6000
1
0.0.0-canary-cc6e663
0
0.0.0-canary-49646971
0.0.0-canary-91f2bb95294708297d0d88248e09b1c0dc454c791
0.0.0-canary-e0b74da3ea9d55d9656fc32c52c6b740383f47de0
0.0.0-canary-5bbd7ad56b530e283b07cff950de61d6af81f00c1
3.21.2-canary.0
0
3.22.0-canary.0
0
3.21.1
4,672
3.21.0-canary.0
0
3.20.1-canary.0
0
3.20.0
6,586
3.19.5
2,916
3.19.4
2,661
3.19.3
690
3.19.2
0
3.19.1
4,515
3.19.0
1,024
3.19.0-canary.0
2
3.18.1
303
3.18.0
463
3.18.0-canary.0
0
3.17.6
3,815
3.17.5
39
3.17.4
725
3.17.3
1,916
3.17.2
9,768
3.17.1
1,505
3.17.0
205
3.16.0
1,132
3.15.6-canary.0
0
3.15.5
384
3.15.4
518
3.15.3
2,320
3.15.3-canary.0
0
3.15.2
1,156
3.15.1
1
3.15.1-canary.1
0
3.16.0-canary.4
2
3.16.0-canary.3
1
3.16.0-canary.2
0
3.16.0-canary.1
1
3.16.0-canary.0
0
3.15.1-canary.0
0
3.16.0-0b5af1a.0
1
3.16.0-dc8fb0d.0
1
3.16.0-alpha.0
0
3.15.0
2,113
3.14.1
4,843
3.14.0
1,070
3.13.0
1,238
3.12.2
419
3.12.1
10
3.12.0
416
3.11.3
1,314
3.11.2
49
3.11.1
1,219
3.11.0
179
3.10.0
959
3.9.5
339
3.9.4
2,137
3.9.3
83
3.9.2
452
3.9.1
802
3.9.0
265
3.8.0
247
3.7.0
375
3.6.0
117
3.6.0-alpha.10
3.5.4
325
3.5.3
443
3.5.2
85
3.5.1
227
3.5.0
81
3.4.5
76
3.4.4
366
3.4.3
15
3.4.2
188
3.4.1
3,338
3.4.0
404
3.3.3
52
3.3.2
373
3.3.1
352
3.3.0
4
3.2.5
45
3.2.4
54
3.2.3
5
3.2.2
6
3.2.1
33
3.2.0
38
3.1.4
165
3.1.3
62
3.1.2
49
3.1.1
4
3.1.0
16
3.0.3
34
3.0.2
2
3.0.1
1
3.0.00
2.22.1
7,101
2.22.0
0
3.0.0-rc.6571
3.0.0-rc.57
2.21.0
344
2.20.2
683
2.20.1
81
3.0.0-beta.31,458
3.0.0-beta.2820
2.20.0
419
2.19.4
1
2.19.3
1
2.19.2
6
3.0.0-beta.112
0.0.0-package-boundaries-16
2.19.1
547
0.0.0-package-boundaries.00
2.19.0
148
2.18.0
25
2.17.5
161
2.17.5-alpha.10
2.17.4
4
2.17.4-alpha.10
2.17.3
0
2.17.2
0
2.17.2-alpha.31
2.17.2-alpha.20
2.17.2-alpha.10
2.17.1
7
2.17.0
23
2.16.0
1
2.15.1
48
2.15.0
0
2.14.6
275
2.14.340
2.14.231
2.14.163
2.14.043
2.13.4777
2.13.2259
2.13.124
2.13.017
2.13.0-beta.21
2.13.0-beta.112
2.12.0284
2.12.0-alpha.10
2.11.061
2.11.0-useFormatter-alpha.10
2.10.4117
2.10.31
2.11.0-alpha.20
2.10.2137
2.11.0-alpha.11
2.10.11
2.10.00
2.10.0-alpha.41
2.9.22
2.10.0-alpha.30
2.9.2-alpha.01
2.9.1111
2.9.011
2.8.00
2.7.7-alpha.01
2.7.626
2.7.537
2.7.4318
2.7.4-alpha.21
2.7.30
2.7.3-alpha.00
2.7.25
2.7.2-alpha.12
2.7.116
2.7.1-alpha.50
2.7.1-alpha.41
2.7.1-alpha.20
2.7.1-alpha.10
2.7.1-alpha.01
2.7.00
2.6.00
2.5.00
2.4.1-alpha.50
2.4.1-alpha.41
2.4.1-alpha.32
2.4.1-alpha.20
2.4.1132
2.4.1-alpha.10
2.4.088
2.3.542
2.3.427
2.3.30
2.3.21
2.3.10
2.3.03
2.2.127
2.2.07
2.1.13
2.1.011
2.0.58
2.0.40
2.0.311
2.0.20
2.0.16
2.0.00
2.0.0-alpha.10
1.5.145
1.5.00
1.4.71
1.4.60
1.4.50
1.4.41
1.4.30
1.4.3-alpha.50
1.4.3-alpha.42
1.3.37
1.3.20
1.3.11
1.3.1-alpha.00
0.1.1-alpha.311
1.3.00
1.2.00
1.1.01
1.0.00
0.3.269
0.3.13
0.3.01
0.2.00
0.1.01
0.0.11

Package Sidebar

Install

npm i use-intl

Weekly Downloads

468,483

Version

4.1.0

License

MIT

Unpacked Size

83.2 kB

Total Files

55

Last publish

Collaborators

  • amann