Added usage documentation with multiple location files

How to use react-native-i18n with multiple locale files & ES6.
This commit is contained in:
marudy 2017-05-14 21:43:34 +03:00 committed by GitHub
parent f880676170
commit 5cab05369c

View File

@ -98,6 +98,44 @@ I18n.translations = {
This will render `Hi!` for devices with the English locale, and `Bonjour!` for devices with the French locale. This will render `Hi!` for devices with the English locale, and `Bonjour!` for devices with the French locale.
## Usage with multiple location files
```javascript
// app/i18n/locales/en.js
export default {
greeting: 'Hi!'
};
// app/i18n/locales/fr.js
export default {
greeting: 'Bonjour!'
};
// app/i18n/i18n.js
import I18n from 'react-native-i18n';
import en from './locales/en';
import es from './locales/es';
I18n.fallbacks = true;
I18n.translations = {
en,
fr
};
export default I18n;
// usage in component
import I18n from 'app/i18n/i18n';
class Demo extends React.Component {
render () {
return (
<Text>{I18n.t('greeting')}</Text>
)
}
}
```
### Fallbacks ### 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): 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-US