|
| 1 | +# react-native-swipe-container |
| 2 | + |
| 3 | +React Multilanguage Higher Order Component. |
| 4 | + |
| 5 | +Works with React and React Native |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +`npm i -S react-multi-lang` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +See the example folder for better understanding |
| 14 | + |
| 15 | +```javascript |
| 16 | +// @flow |
| 17 | + |
| 18 | +import * as React from 'react' |
| 19 | + |
| 20 | +// Translation Higher Order Component |
| 21 | +import { setTranslations, setDefaultLanguage, translate } from 'react-multi-lang' |
| 22 | +import pt from '.pt.json' |
| 23 | +import en from '.en.json' |
| 24 | + |
| 25 | +// Do this two lines only when setting up the application |
| 26 | +setTranslations({pt, en}) |
| 27 | +setDefaultLanguage('en') |
| 28 | + |
| 29 | +type Props = { |
| 30 | + translate:(string) => string |
| 31 | +} |
| 32 | + |
| 33 | +type State = {} |
| 34 | + |
| 35 | +class SomeComponent extends React.Component<Props, State> { |
| 36 | + render () { |
| 37 | + const { translate } = this.props |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + {translate('About Us')} |
| 41 | + </div> |
| 42 | + ) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +export default translate(SomeComponent) |
| 47 | +``` |
| 48 | + |
| 49 | +## Injected Method |
| 50 | + |
| 51 | +#### translate(key) |
| 52 | + |
| 53 | +| Params | Type | Description | |
| 54 | +| ------------- |:-------------:| ------------ | |
| 55 | +| key | string | translation key that identifies the text | |
| 56 | + |
| 57 | + |
| 58 | +## Methods |
| 59 | + |
| 60 | +#### setTranslations(translations) |
| 61 | + |
| 62 | +| Params | Type | Description | |
| 63 | +| ------------- |:-------------:| ------------ | |
| 64 | +| translations | object | {'key': 'translations', ...} | |
| 65 | + |
| 66 | +#### setDefaultLanguage(key) |
| 67 | + |
| 68 | +| Params | Type | Description | |
| 69 | +| ------------- |:-------------:| ------------ | |
| 70 | +| key | string | translation key, in this example 'en' or 'pt' | |
0 commit comments