Skip to content

Commit 646b4b3

Browse files
author
Joao Moura
committed
Added readme
1 parent c108321 commit 646b4b3

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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' |

example/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import en from './translations/en.json'
1111
// Translated Component
1212
import TranslatedComponent from './component'
1313

14-
setDefaultLanguage('en')
1514
setTranslations({pt, en})
15+
setDefaultLanguage('en')
1616

1717
ReactDOM.render(
1818
<TranslatedComponent/>,

0 commit comments

Comments
 (0)