You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
103
102
## Usage
104
103
105
104
```javascript
106
-
importI18nfrom'react-native-i18n'
105
+
importI18nfrom'react-native-i18n';
106
+
// OR const I18n = require('react-native-i18n').default
107
107
108
108
classDemoextendsReact.Component {
109
-
render () {
110
-
return (
111
-
<Text>{I18n.t('greeting')}</Text>
112
-
)
109
+
render() {
110
+
return<Text>{I18n.t('greeting')}</Text>;
113
111
}
114
112
}
115
113
116
114
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
117
-
I18n.fallbacks=true
115
+
I18n.fallbacks=true;
118
116
119
117
I18n.translations= {
120
118
en: {
121
-
greeting:'Hi!'
119
+
greeting:'Hi!',
122
120
},
123
121
fr: {
124
-
greeting:'Bonjour!'
125
-
}
126
-
}
122
+
greeting:'Bonjour!',
123
+
},
124
+
};
127
125
```
128
126
129
127
This will render `Hi!` for devices with the English locale, and `Bonjour!` for devices with the French locale.
@@ -147,7 +145,7 @@ export default {
147
145
148
146
importI18nfrom'react-native-i18n';
149
147
importenfrom'./locales/en';
150
-
importfrfrom'./locales/fr';
148
+
importfrfrom'./locales/fr';
151
149
152
150
I18n.fallbacks=true;
153
151
@@ -156,7 +154,7 @@ I18n.translations = {
156
154
fr
157
155
};
158
156
159
-
exportdefaultI18n;
157
+
exportdefaultI18n;
160
158
161
159
// usage in component
162
160
@@ -172,23 +170,25 @@ class Demo extends React.Component {
172
170
```
173
171
174
172
### Fallbacks
173
+
175
174
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
178
178
179
179
**Note**: iOS 8 locales use underscored (`en_US`) but `i18n.js` locales are dasherized (`en-US`). This conversion is done automatically for you.
180
180
181
181
```javascript
182
-
I18n.fallbacks=true
182
+
I18n.fallbacks=true;
183
183
184
184
I18n.translations= {
185
-
'en': {
186
-
greeting:'Hi!'
185
+
en: {
186
+
greeting:'Hi!',
187
187
},
188
188
'en-GB': {
189
-
greeting:'Hi from the UK!'
190
-
}
191
-
}
189
+
greeting:'Hi from the UK!',
190
+
},
191
+
};
192
192
```
193
193
194
194
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
198
198
You can get the user preferred locales with the `getLanguages` method:
199
199
200
200
```javascript
201
-
import { getLanguages } from'react-native-i18n'
201
+
import { getLanguages } from'react-native-i18n';
202
202
203
203
getLanguages().then(languages=> {
204
-
console.log(languages) // ['en-US', 'en']
205
-
})
204
+
console.log(languages);// ['en-US', 'en']
205
+
});
206
206
```
207
207
208
-
209
208
### I18n.js documentation
210
209
211
210
For more info about I18n.js methods (`localize`, `pluralize`, etc) and settings see [its documentation](https://github.com/fnando/i18n-js#setting-up).
0 commit comments