diff --git a/README.md b/README.md index 4509e92..a2c253b 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,6 @@ protected List getPackages() { } // ... - ``` 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 ## 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 ( - {I18n.t('greeting')} - ) + render() { + return {I18n.t('greeting')}; } } // 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. @@ -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; @@ -156,7 +154,7 @@ I18n.translations = { fr }; -export default I18n; +export default I18n; // usage in component @@ -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!`. @@ -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). diff --git a/index.js b/index.js index f0250f3..6402f5a 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index b6fb474..0fbc0e5 100644 --- a/package.json +++ b/package.json @@ -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",