use-intl

esm
Internationalization (i18n) for React
Version 4.3.4 License MIT
Keywords
reactintli18ninternationalizationlocalizationtranslatetranslationformatformatting
INSTALL
Type:
Version:
- Static
- Latest Patch
- Latest Minor
- Latest Major
- 4.3.4
- 4.3.3
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.26.5
- 3.26.4
- 3.26.3
- 3.26.2
- 3.26.1
- 3.26.0
- 3.25.3
- 3.25.2
- 3.25.1
- 3.25.0
- 3.24.0
- 3.23.5
- 3.23.4
- 3.23.3
- 3.23.2
- 3.23.1
- 3.23.0
- 3.22.0
- 3.21.1
- 3.20.0
- 3.19.5
- 3.19.4
- 3.19.3
- 3.19.2
- 3.19.1
- 3.19.0
- 3.18.1
- 3.18.0
- 3.17.6
- 3.17.5
- 3.17.4
- 3.17.3
- 3.17.2
- 3.17.1
- 3.17.0
- 3.16.0
- 3.15.5
- 3.15.4
- 3.15.3
- 3.15.2
- 3.15.1
- 3.15.0
- 3.14.1
- 3.14.0
- 3.13.0
- 3.12.2
- 3.12.1
- 3.12.0
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.0
- 3.7.0
- 3.6.0
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.22.3
- 2.22.2
- 2.22.1
- 2.22.0
- 2.21.0
- 2.20.2
- 2.20.1
- 2.20.0
- 2.19.4
- 2.19.3
- 2.19.2
- 2.19.1
- 2.19.0
- 2.18.0
- 2.17.5
- 2.17.4
- 2.17.3
- 2.17.2
- 2.17.1
- 2.17.0
- 2.16.0
- 2.15.1
- 2.15.0
- 2.14.6
- 2.14.3
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.4
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.4
- 2.10.3
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.0
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.5.1
- 1.5.0
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.1
- 4.0.0-beta-f511797
- 4.0.0-beta-f10dbba
- 4.0.0-beta-dea867b
- 4.0.0-beta-ddd5ae5
- 4.0.0-beta-db95243
- 4.0.0-beta-ca68f02
- 4.0.0-beta-ca3fcd5
- 4.0.0-beta-c8eb4ad
- 4.0.0-beta-c4c5986
- 4.0.0-beta-c40c5c9
- 4.0.0-beta-c323050
- 4.0.0-beta-bae1131
- 4.0.0-beta-9ea117c
- 4.0.0-beta-9e73cbe
- 4.0.0-beta-8f37883
- 4.0.0-beta-8cce53e
- 4.0.0-beta-7e7011d
- 4.0.0-beta-7b755e9
- 4.0.0-beta-77949ef
- 4.0.0-beta-67507cc
- 4.0.0-beta-5ec7f45
- 4.0.0-beta-5b218d4
- 4.0.0-beta-5a7f7be
- 4.0.0-beta-4106641
- 4.0.0-beta-40d535a
- 4.0.0-beta-32fc4e3
- 4.0.0-beta-22cf1cd
- 4.0.0-beta-1a5e0ec
- 4.0.0-beta-18156c4
- 4.0.0-beta-0825f08
- 4.0.0-beta-021e874
- 4.0.0-beta-00a79d4
- 3.22.0-canary.0
- 3.21.2-canary.0
- 3.21.0-canary.0
- 3.20.1-canary.0
- 3.19.0-canary.0
- 3.18.0-canary.0
- 3.16.0-dc8fb0d.0
- 3.16.0-canary.4
- 3.16.0-canary.3
- 3.16.0-canary.2
- 3.16.0-canary.1
- 3.16.0-canary.0
- 3.16.0-alpha.0
- 3.16.0-0b5af1a.0
- 3.15.6-canary.0
- 3.15.3-canary.0
- 3.15.1-canary.1
- 3.15.1-canary.0
- 3.6.0-alpha.1
- 3.0.0-rc.6
- 3.0.0-rc.5
- 3.0.0-beta.3
- 3.0.0-beta.2
- 3.0.0-beta.1
- 2.17.5-alpha.1
- 2.17.4-alpha.1
- 2.17.2-alpha.3
- 2.17.2-alpha.2
- 2.17.2-alpha.1
- 2.13.0-beta.2
- 2.13.0-beta.1
- 2.12.0-alpha.1
- 2.11.0-useFormatter-alpha.1
- 2.11.0-alpha.2
- 2.11.0-alpha.1
- 2.10.0-alpha.4
- 2.10.0-alpha.3
- 2.9.2-alpha.0
- 2.7.7-alpha.0
- 2.7.4-alpha.2
- 2.7.3-alpha.0
- 2.7.2-alpha.1
- 2.7.1-alpha.5
- 2.7.1-alpha.4
- 2.7.1-alpha.2
- 2.7.1-alpha.1
- 2.7.1-alpha.0
- 2.4.1-alpha.5
- 2.4.1-alpha.4
- 2.4.1-alpha.3
- 2.4.1-alpha.2
- 2.4.1-alpha.1
- 2.0.0-alpha.1
- 1.4.3-alpha.5
- 1.4.3-alpha.4
- 1.3.1-alpha.0
- 0.1.1-alpha.31
- 0.0.0-package-boundaries-1
- 0.0.0-package-boundaries.0
- 0.0.0-canary-fdaddc5
- 0.0.0-canary-e0b74da3ea9d55d9656fc32c52c6b740383f47de
- 0.0.0-canary-cc6e663
- 0.0.0-canary-b73586f
- 0.0.0-canary-a205821
- 0.0.0-canary-92d8a58
- 0.0.0-canary-91f2bb95294708297d0d88248e09b1c0dc454c79
- 0.0.0-canary-84fe6d0
- 0.0.0-canary-7b3a9a3
- 0.0.0-canary-5bbd7ad56b530e283b07cff950de61d6af81f00c
- 0.0.0-canary-58b4a57
- 0.0.0-canary-4ada87c
- 0.0.0-canary-4964697
- 0.0.0-canary-282196c
- 0.0.0-canary-255c5c2
- 0.0.0-canary-0ea6000
- 0.0.0-canary-0b8e3a5
- 0.0.0-canary-09b34ea
<script src=" https://cdn.jsdelivr.net/npm/use-intl@4.3.4/dist/esm/production/index.min.js "></script>
🌐 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
npm install use-intl
- Add the provider
- 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.