From 5cab05369ceb1cd70862cc53049ae23bc26cc25d Mon Sep 17 00:00:00 2001 From: marudy Date: Sun, 14 May 2017 21:43:34 +0300 Subject: [PATCH] Added usage documentation with multiple location files How to use react-native-i18n with multiple locale files & ES6. --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index b27ee88..1c6d2f2 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,44 @@ I18n.translations = { 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 ( + {I18n.t('greeting')} + ) + } +} +``` + ### 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