React Intl

实现 React 应用程序的国际化。该库提供 React 组件和 API,用于格式化日期、数字和字符串,包括复数化和处理翻译。「Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.」

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者formatjs/formatjs
主編程語言TypeScript
編程語言JavaScript (語言數: 9)
平台
許可證
所有者活动
創建於2014-04-24 17:28:36
推送於2025-04-22 06:54:18
最后一次提交
發布數3457
最新版本名稱react-intl@7.1.11 (發布於 2025-04-18 22:45:48)
第一版名稱v0.1.0-rc-1 (發布於 )
用户参与
星數14.5k
關注者數130
派生數1.4k
提交數5.5k
已啟用問題?
問題數1978
打開的問題數24
拉請求數1395
打開的拉請求數16
關閉的拉請求數1303
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?