Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
GCoder-13 committed Sep 12, 2019
1 parent c7c2a1f commit e1cadf8
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ import { withTranslate } from 'gc-translate'
@withTranslate
export default class Main extends Compenent {
render () {
const { tr } = this.props
const { intl } = this.props

return (
<h1>{ tr.dictionary.title }</h1>
<h2>{ tr.getTranslate('Main.example', { num: 1 }) }</h2>
<p>{ tr.getTranslate(['Main', 'info']) }</p>
<h1>{ intl.tr.title }</h1>
<h2>{ intl.tr('Main.example', { num: 1 }) }</h2>
<p>{ intl.tr(['Main', 'info']) }</p>
<div>
<button onClick={() => { tr.changeLanguage('en') }}>En</button>
<button onClick={() => { tr.changeLanguage('ru') }}>Ru</button>
<button onClick={() => { intl.changeLang('en') }}>En</button>
<button onClick={() => { intl.changeLang('ru') }}>Ru</button>
</div>
)
}
Expand All @@ -66,10 +66,10 @@ import Main from 'Main';

ReactDOM.render(
<TrProvider
defaultLanguage='en'
defaultLang='en'
dictionaries={{
en: () => import('lang/en.json'),
ru: () => import('lang/ru.json'),
en: () => import('./lang/en.json'),
ru: () => import('./lang/ru.json'),
}}
>
<Main />
Expand All @@ -90,23 +90,30 @@ import { TrProvider } from 'gc-translate'
```
```xml
<TrProvider
defaultLanguage={string}
defaultLang={string}
dictionaries={object}
>
{/* render something */}
<TrProvider/>
```

#### Properties
*defaultLanguage* (**required**) - default language from the dictionaries list
*defaultLang* (**required**) - default language from the dictionaries list

*dictionaries* (**required**) - list of connected json files with translations
*dictionaries* (**required**) - list of connected json files or objects with translations ([Dictionary](#dictionary))
```js
{
en: () => import('lang/en.json'),
ru: () => import('lang/ru.json'),
}
```
or
```js
{
en: { /* Object with translations */ },
ru: { /* Object with translations */ },
}
```


### `TrConsumer`
Expand All @@ -133,15 +140,15 @@ import { withTranslate } from 'gc-translate'
@withTranslate
class Page extends Compenent {
render () {
const { tr } = this.props;
const { intl } = this.props;

/* render something based on the context value */
}
}
```

#### Props
*tr* - [context object](#context) with translations and handling translations
*intl* - [context object](#context) with translations and handling translations


### `TrContext`
Expand All @@ -155,9 +162,9 @@ class Page extends Compenent {

render () {
const {
dictionary,
getTranslate,
changeLanguage,
tr,
lang,
changeLang,
} = this.context;

/* render something based on the context value */
Expand All @@ -167,36 +174,43 @@ class Page extends Compenent {


### Context
#### `dictionary`
Data json-file with translations

**Example:**
```json
{
"title": "My application",
"Main": {
"info": "Hello world",
"example": "Example {num}"
}
}
```
#### `lang`
The value of the current language

#### `tr`
Object with translations [dictionary](#dictionary)

#### `getTranslate(path[, options])`
#### `tr(path[, options])`
Function for translation

**Arguments:**

*path* (**required**) - path of object [dictionary](#dictionary)

*options* - object options for replace in value at path of dictionary

#### `changeLanguage(newLanguage)`
#### `changeLang(newLanguage)`
Function for changing the current language

### Dictionary
Data with translations

**Example:**
```json
{
"title": "My application",
"Main": {
"info": "Hello world",
"example": "Example {num}"
}
}
```

## License
This software is free to use under the MIT license.
See the [LICENSE file][] for license text and copyright information.


[react]: http://facebook.github.io/react/
[license file]: https://github.com/gc-web-group/gc-translate/blob/master/LICENSE
[license file]: https://github.com/gc-web-group/gc-translate/blob/master/LICENSE

0 comments on commit e1cadf8

Please sign in to comment.