Skip to content
Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.
TypeScript JavaScript
Branch: master
Clone or download

Latest commit

Latest commit 1e61bd3 Apr 14, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github chore: add node 13 Jan 9, 2020
docs feat: add `defineMessage` macro to tag single message Apr 14, 2020
examples feat: add `defineMessage` macro to tag single message Apr 14, 2020
scripts chore: fix lint issues, include a single bundled d.ts file Nov 21, 2019
src feat: add `defineMessage` macro to tag single message Apr 14, 2020
test chore: add more tests Apr 14, 2020
.eslintignore chore: fix lint issues, include a single bundled d.ts file Nov 21, 2019
.eslintrc chore: fix lint issues, include a single bundled d.ts file Nov 21, 2019
.gitignore chore: use api-extractor to generate a single d.ts Nov 21, 2019
.prettierignore chore: dont prettier CHANGELOG since its auto-gen Aug 2, 2019
.prettierrc chore: rm some custom utils impl (#1315) Jun 12, 2019
.travis.yml chore: fix build for windows Aug 12, 2019
CHANGELOG.md chore(release): 4.4.0 Apr 14, 2020
CONTRIBUTING.md chore: s/Yahoo/Oath, fix contributing guidelines Nov 23, 2019
LICENSE.md chore: s/Yahoo/Oath, fix contributing guidelines Nov 23, 2019
README.md feat: add `defineMessage` macro to tag single message Apr 14, 2020
api-extractor.bundled.json fix: include intl-displaynames types in bundled react-intl.d.ts Mar 21, 2020
api-extractor.json chore: use api-extractor to generate a single d.ts Nov 21, 2019
babel.config.js add tsconfig.json and setup pipeline to use ts compiler (#1311) Jun 13, 2019
jest.config.js fix: remove contextType usage Aug 9, 2019
package-lock.json chore(release): 4.4.0 Apr 14, 2020
package.json chore(release): 4.4.0 Apr 14, 2020
rollup.config.dist.js chore: update docs to highlight DOMParser Aug 21, 2019
tsconfig.cjs.json feat: expose a core bundle w/o parser (#1358) Jul 9, 2019
tsconfig.json fix: turn on preserveConstEnums so we export ReactIntlErrorCode Mar 21, 2020

README.md

React Intl

Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.

npm Version npm Version Build Status

minified size minzipped size

Overview

React Intl is part of FormatJS. It provides bindings to React via its components and API.

Slack: Join us on Slack at formatjs.slack.com for help, general conversation and more 💬🎊🎉 You can sign-up using this invitation link.

Documentation

React Intl's docs are in this GitHub /docs folder, Get Started. There are also several runnable example apps which you can reference to learn how all the pieces fit together.

(If you're looking for React Intl v1, you can find it here.)

Features

  • Display numbers with separators.
  • Display dates and times correctly.
  • Display dates relative to "now".
  • Pluralize labels in strings.
  • Support for 150+ languages.
  • Runs in the browser and Node.js.
  • Built on standards.

Example

There are several runnable examples in this Git repo, but here's a Hello World one:

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {IntlProvider, FormattedMessage} from 'react-intl';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      name: 'Eric',
      unreadCount: 1000,
    };
  }

  render() {
    const {name, unreadCount} = this.state;

    return (
      <p>
        <FormattedMessage
          id="welcome"
          defaultMessage={`Hello {name}, you have {unreadCount, number} {unreadCount, plural,
                      one {message}
                      other {messages}
                    }`}
          values={{name: <b>{name}</b>, unreadCount}}
        />
      </p>
    );
  }
}

ReactDOM.render(
  <IntlProvider locale="en">
    <App />
  </IntlProvider>,
  document.getElementById('container')
);

This example would render: "Hello Eric, you have 1,000 messages." into the container element on the page.

Pluralization rules: In some languages you have more than one and other. For example in ru there are the following plural rules: one, few, many and other. Check out the official Unicode CLDR documentation.

Contribute

Let's make React Intl and FormatJS better! If you're interested in helping, all contributions are welcome and appreciated. React Intl is just one of many packages that make up the FormatJS suite of packages, and you can contribute to any/all of them, including the Format JS website itself.

Check out the Contributing document for the details. Thanks!

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.

You can’t perform that action at this time.