Skip to content

Commit

Permalink
Revert to ES modules, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Feb 5, 2018
1 parent bb06f6f commit 1dc8885
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ protected List<ReactPackage> getPackages() {
}

// ...

```

After that, you will need to recompile your project with `react-native run-android`.
Expand All @@ -103,27 +102,26 @@ After that, you will need to recompile your project with `react-native run-andro
## Usage

```javascript
import I18n from 'react-native-i18n'
import I18n from 'react-native-i18n';
// OR const I18n = require('react-native-i18n').default

class Demo extends React.Component {
render () {
return (
<Text>{I18n.t('greeting')}</Text>
)
render() {
return <Text>{I18n.t('greeting')}</Text>;
}
}

// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
I18n.fallbacks = true
I18n.fallbacks = true;

I18n.translations = {
en: {
greeting: 'Hi!'
greeting: 'Hi!',
},
fr: {
greeting: 'Bonjour!'
}
}
greeting: 'Bonjour!',
},
};
```

This will render `Hi!` for devices with the English locale, and `Bonjour!` for devices with the French locale.
Expand All @@ -147,7 +145,7 @@ export default {

import I18n from 'react-native-i18n';
import en from './locales/en';
import fr from './locales/fr';
import fr from './locales/fr';

I18n.fallbacks = true;

Expand All @@ -156,7 +154,7 @@ I18n.translations = {
fr
};

export default I18n;
export default I18n;

// usage in component

Expand All @@ -172,23 +170,25 @@ class Demo extends React.Component {
```

### Fallbacks

When fallbacks are enabled (which is generally recommended), `i18n.js` will try to look up translations in the following order (for a device with `en_US` locale):
- en-US
- en

* en-US
* en

**Note**: iOS 8 locales use underscored (`en_US`) but `i18n.js` locales are dasherized (`en-US`). This conversion is done automatically for you.

```javascript
I18n.fallbacks = true
I18n.fallbacks = true;

I18n.translations = {
'en': {
greeting: 'Hi!'
en: {
greeting: 'Hi!',
},
'en-GB': {
greeting: 'Hi from the UK!'
}
}
greeting: 'Hi from the UK!',
},
};
```

For a device with a `en_GB` locale this will return `Hi from the UK!'`, for a device with a `en_US` locale it will return `Hi!`.
Expand All @@ -198,14 +198,13 @@ For a device with a `en_GB` locale this will return `Hi from the UK!'`, for a de
You can get the user preferred locales with the `getLanguages` method:

```javascript
import { getLanguages } from 'react-native-i18n'
import { getLanguages } from 'react-native-i18n';

getLanguages().then(languages => {
console.log(languages) // ['en-US', 'en']
})
console.log(languages); // ['en-US', 'en']
});
```


### I18n.js documentation

For more info about I18n.js methods (`localize`, `pluralize`, etc) and settings see [its documentation](https://github.com/fnando/i18n-js#setting-up).
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ if (typeof RNI18n !== 'undefined') {
console.warn('react-native-i18n module is not correctly linked');
}

I18nJs.getLanguages = () => RNI18n.getLanguages();
module.exports = I18nJs;
export const getLanguages = () => RNI18n.getLanguages();
export default I18nJs;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-i18n",
"version": "2.0.11",
"version": "2.0.12",
"description": "Provide I18n to your React Native application",
"license": "MIT",
"author": "Alexander Zaytsev",
Expand Down

0 comments on commit 1dc8885

Please sign in to comment.