|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/frostney/react-intl-native) [](https://david-dm.org/frostney/react-intl-native) [](https://david-dm.org/frostney/react-intl-native#info=devDependencies) [](https://codecov.io/github/frostney/react-intl-native?branch=master)
|
4 | 4 |
|
5 |
| -react-intl components for React Native |
| 5 | +`react-intl` convinience components for React Native |
| 6 | + |
| 7 | +While `react-intl` allows us to use `formatMessage` or passing in a function, this becomes tiresome if you have to do this for each. This module does the latter and wraps it all in a `Text` component allowing you to pass in `style` to provide custom styling. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +``` |
| 12 | +$ npm install react-intl-native |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Wrap your main component inside `react-intl`s `IntlProvider` like you would in your web application: |
| 18 | + |
| 19 | +```javascript |
| 20 | +import IntlProvider from 'react-intl'; |
| 21 | +``` |
| 22 | + |
| 23 | +```jsx |
| 24 | +<IntlProvider locale="en"> |
| 25 | + <MainView /> |
| 26 | +</IntlProvider> |
| 27 | +``` |
| 28 | + |
| 29 | +#### FormattedDate |
| 30 | + |
| 31 | +```jsx |
| 32 | +<FormattedDate |
| 33 | + weekday="long" |
| 34 | + value={Date.now()} |
| 35 | + style={{ fontWeight: 'bold' }} /> |
| 36 | +``` |
| 37 | + |
| 38 | +More information on date formatting options: https://github.com/yahoo/react-intl/wiki/Components#date-formatting-components |
| 39 | + |
| 40 | +#### FormattedHTMLMessage |
| 41 | + |
| 42 | +```jsx |
| 43 | +<FormattedHTMLMessage |
| 44 | + defaultMessage="Hello there" |
| 45 | + style={{ fontWeight: 'bold' }} /> |
| 46 | +``` |
| 47 | + |
| 48 | +#### FormattedMessage |
| 49 | + |
| 50 | +```jsx |
| 51 | +<FormattedMessage |
| 52 | + defaultMessage="Hello there" |
| 53 | + style={{ fontWeight: 'bold' }} /> |
| 54 | +``` |
| 55 | + |
| 56 | +#### FormattedNumber |
| 57 | +This is the only component that differs slightly from the original component. For the formatting style you need to use `formatStyle` instead of `style`. `style` is being reserved for the component styling. |
| 58 | + |
| 59 | +```jsx |
| 60 | +<FormattedNumber |
| 61 | + formatStyle="currency" |
| 62 | + value={1000} |
| 63 | + style={{ fontWeight: 'bold' }} /> |
| 64 | +``` |
| 65 | + |
| 66 | +More information on number formatting options: https://github.com/yahoo/react-intl/wiki/Components#formattednumber |
| 67 | + |
| 68 | +#### FormattedPlural |
| 69 | + |
| 70 | +```jsx |
| 71 | +<FormattedPlural |
| 72 | + value={10} |
| 73 | + one="message" |
| 74 | + other="messages" |
| 75 | + style={{ fontWeight: 'bold' }} /> |
| 76 | +``` |
| 77 | + |
| 78 | +More information on plural formatting options: https://github.com/yahoo/react-intl/wiki/Components#formattedplural |
| 79 | + |
| 80 | +#### FormattedRelative |
| 81 | + |
| 82 | +```jsx |
| 83 | +<FormattedRelative |
| 84 | + value={Date.now()} |
| 85 | + style={{ fontWeight: 'bold' }} /> |
| 86 | +``` |
| 87 | + |
| 88 | +More information on date formatting options: https://github.com/yahoo/react-intl/wiki/Components#date-formatting-components |
| 89 | + |
| 90 | +#### FormattedTime |
| 91 | + |
| 92 | +```jsx |
| 93 | +<FormattedTime |
| 94 | + value={Date.now()} |
| 95 | + hour="numeric" |
| 96 | + style={{ fontWeight: 'bold' }} /> |
| 97 | +``` |
| 98 | + |
| 99 | +More information on date formatting options: https://github.com/yahoo/react-intl/wiki/Components#date-formatting-components |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +For more information, take a look the `react-intl` documentation: https://github.com/yahoo/react-intl/wiki/Components |
| 104 | + |
| 105 | +## License |
| 106 | + |
| 107 | +MIT |
0 commit comments