Skip to content

Commit 1dc8885

Browse files
committed
Revert to ES modules, update README
1 parent bb06f6f commit 1dc8885

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ protected List<ReactPackage> getPackages() {
9191
}
9292

9393
// ...
94-
9594
```
9695

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

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

108108
class Demo extends React.Component {
109-
render () {
110-
return (
111-
<Text>{I18n.t('greeting')}</Text>
112-
)
109+
render() {
110+
return <Text>{I18n.t('greeting')}</Text>;
113111
}
114112
}
115113

116114
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
117-
I18n.fallbacks = true
115+
I18n.fallbacks = true;
118116

119117
I18n.translations = {
120118
en: {
121-
greeting: 'Hi!'
119+
greeting: 'Hi!',
122120
},
123121
fr: {
124-
greeting: 'Bonjour!'
125-
}
126-
}
122+
greeting: 'Bonjour!',
123+
},
124+
};
127125
```
128126

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

148146
import I18n from 'react-native-i18n';
149147
import en from './locales/en';
150-
import fr from './locales/fr';
148+
import fr from './locales/fr';
151149

152150
I18n.fallbacks = true;
153151

@@ -156,7 +154,7 @@ I18n.translations = {
156154
fr
157155
};
158156

159-
export default I18n;
157+
export default I18n;
160158

161159
// usage in component
162160

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

174172
### Fallbacks
173+
175174
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):
176-
- en-US
177-
- en
175+
176+
* en-US
177+
* en
178178

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

181181
```javascript
182-
I18n.fallbacks = true
182+
I18n.fallbacks = true;
183183

184184
I18n.translations = {
185-
'en': {
186-
greeting: 'Hi!'
185+
en: {
186+
greeting: 'Hi!',
187187
},
188188
'en-GB': {
189-
greeting: 'Hi from the UK!'
190-
}
191-
}
189+
greeting: 'Hi from the UK!',
190+
},
191+
};
192192
```
193193

194194
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!`.
@@ -198,14 +198,13 @@ For a device with a `en_GB` locale this will return `Hi from the UK!'`, for a de
198198
You can get the user preferred locales with the `getLanguages` method:
199199

200200
```javascript
201-
import { getLanguages } from 'react-native-i18n'
201+
import { getLanguages } from 'react-native-i18n';
202202

203203
getLanguages().then(languages => {
204-
console.log(languages) // ['en-US', 'en']
205-
})
204+
console.log(languages); // ['en-US', 'en']
205+
});
206206
```
207207

208-
209208
### I18n.js documentation
210209

211210
For more info about I18n.js methods (`localize`, `pluralize`, etc) and settings see [its documentation](https://github.com/fnando/i18n-js#setting-up).

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ if (typeof RNI18n !== 'undefined') {
1111
console.warn('react-native-i18n module is not correctly linked');
1212
}
1313

14-
I18nJs.getLanguages = () => RNI18n.getLanguages();
15-
module.exports = I18nJs;
14+
export const getLanguages = () => RNI18n.getLanguages();
15+
export default I18nJs;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-i18n",
3-
"version": "2.0.11",
3+
"version": "2.0.12",
44
"description": "Provide I18n to your React Native application",
55
"license": "MIT",
66
"author": "Alexander Zaytsev",

0 commit comments

Comments
 (0)