Cleanup and added react-native link
This commit is contained in:
parent
93449f3cc8
commit
99290f4d78
33
README.md
33
README.md
|
@ -1,5 +1,3 @@
|
||||||
ATTENTION: This repo is looking for a new developer to take over. Please email me alexander@say26.com.
|
|
||||||
|
|
||||||
# react-native-i18n
|
# react-native-i18n
|
||||||
|
|
||||||
Integrates [I18n.js](https://github.com/fnando/i18n-js) with React Native. Uses the device's locale as default.
|
Integrates [I18n.js](https://github.com/fnando/i18n-js) with React Native. Uses the device's locale as default.
|
||||||
|
@ -8,9 +6,10 @@ Integrates [I18n.js](https://github.com/fnando/i18n-js) with React Native. Uses
|
||||||
|
|
||||||
`$ npm install react-native-i18n --save`
|
`$ npm install react-native-i18n --save`
|
||||||
|
|
||||||
After installing the npm package you need to link the native modules. You can do so using [rnpm](https://github.com/rnpm/rnpm).
|
After installing the npm package you need to link the native modules.
|
||||||
|
If you're using React-Native < 0.29 install [rnpm](https://github.com/rnpm/rnpm) with the command `npm install -g rnpm` and then link the library with the command `rnpm link`.
|
||||||
`$ rnpm link react-native-i18n`
|
If you're using React-Native >= 0.29 just link the library with the command `react-native link`.
|
||||||
|
You can do so using [rnpm](https://github.com/rnpm/rnpm).
|
||||||
|
|
||||||
Or you can do it manually as follows:
|
Or you can do it manually as follows:
|
||||||
|
|
||||||
|
@ -66,19 +65,19 @@ After that, you will need to recompile your project with `react-native run-andro
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var I18n = require('react-native-i18n');
|
import I18n from 'react-native-i18n'
|
||||||
|
|
||||||
var Demo = React.createClass({
|
class Demo extends React.Component {
|
||||||
render: function() {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Text>{I18n.t('greeting')}</Text>
|
<Text>{I18n.t('greeting')}</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
|
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
|
||||||
I18n.fallbacks = true;
|
I18n.fallbacks = true
|
||||||
|
|
||||||
I18n.translations = {
|
I18n.translations = {
|
||||||
en: {
|
en: {
|
||||||
|
@ -99,7 +98,7 @@ When fallbacks are enabled (which is generally recommended), `i18n.js` will try
|
||||||
|
|
||||||
**Note**: iOS locales use underscored (`en_US`) but `i18n.js` locales are dasherized (`en-US`). This conversion is done automatically for you.
|
**Note**: iOS locales use underscored (`en_US`) but `i18n.js` locales are dasherized (`en-US`). This conversion is done automatically for you.
|
||||||
```js
|
```js
|
||||||
I18n.fallbacks = true;
|
I18n.fallbacks = true
|
||||||
|
|
||||||
I18n.translations = {
|
I18n.translations = {
|
||||||
'en': {
|
'en': {
|
||||||
|
@ -117,14 +116,8 @@ For a device with a `en_GB` locale this will return `Hi from the UK!'`, for a de
|
||||||
You can get the device's locale with the `RNI18n` native module:
|
You can get the device's locale with the `RNI18n` native module:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var deviceLocale = require('react-native').NativeModules.RNI18n.locale
|
import ReactNativeI18n from 'react-native-i18n'
|
||||||
```
|
const deviceLocale = ReactNativeI18n.locale
|
||||||
|
|
||||||
Returns `en_US`. You can also do:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var I18n = require('react-native-i18n');
|
|
||||||
var deviceLocale = I18n.locale;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns `en-US`.
|
Returns `en-US`.
|
||||||
|
|
Loading…
Reference in New Issue