Skip to content

Commit

Permalink
chore: update README with more info
Browse files Browse the repository at this point in the history
  • Loading branch information
MiracleUFO committed Nov 17, 2022
1 parent b5b0c30 commit db654f7
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
A modern, *free*, *lightweight* npm package for translating react apps (pages and components) on the fly. *No API keys or language list files* are required.

## Features
- Covers multiple use cases (see ##Usages)
- Covers multiple use cases (see [Usage](#usage))
- Allows to create custom language change component
- Auto language detection
- Spelling and Language correction
- Fast and reliable – it uses the same servers that [translate.google.com](https://translate.google.com) uses
Expand All @@ -14,10 +15,13 @@ A modern, *free*, *lightweight* npm package for translating react apps (pages an
```npm install react-g-translator```

or with yarn

```yarn add react-g-translator```

## Usage
```jsx: To translate whole component.

### To translate whole component:
```jsx
import Translator from 'react-auto-translate';

return (
Expand Down Expand Up @@ -79,62 +83,75 @@ return (
## API
### Props
- `from`: Language text is provided in.
*Type string* [If string provided is not found here, will default to "en"](https://cloud.google.com/translate/docs/languages).
Defaults to "en".
Can be overriden by `setLanguageFrom` hook.
- `from`: Language the text(s) is provided in.
- Defaults to "en".
- *Type string*. If string provided is not found [here](https://cloud.google.com/translate/docs/languages), will default to "en".
- Overriden by [`setLanguageFrom`](#hook-setlanguagefromfrom) hook.
- `to`: Language to translate to.
*Type string* [If string provided is not found here, will default to *user's current browser langauge setting*.](https://cloud.google.com/translate/docs/languages).
Defaults to *user's current browser langauge setting*.
Can be overriden by `setLanguageTo` hook.
- Defaults to *user's current browser langauge setting*.
- *Type string*. If string provided is not found [here](https://cloud.google.com/translate/docs/languages) will default to *user's current browser langauge setting*.
- Overriden by [`setLanguageTo`](#hook-setlanguagetoto) hook.
### Wrapper: `<Translator />` ###
*Type:* React functional component
*Props:*
- `from`
- `to`
- [`from`](#props)
- [`to`](#props)
*Note:*
- Directly wraps a valid Provider or a jsx parent (not text.)
### Wrapper: `<Translate>` ###
### Wrapper: `<Translate />` ###
*Type:* React functional component
*Props:*
- `from`
- `to`
- [`from`](#props)
- [`to`](#props)
*Note:*
- Directly wraps text.
## Hook `useTranslate` ###
### Hook `useTranslate` ###
*Type*: React hook
*Returns*:
- `setLanguageFrom`
- `setLanguageTo`
- `translate`
- [`setLanguageFrom`](#hook-setlanguagefromfrom)
- [`setLanguageTo`](#hook-setlanguagetoto)
- [`translate`](#hook-translatetext-from-to)
## Hook `setLanguageFrom(from)` ###
### Hook `setLanguageFrom(from)` ###
Overrides `from` prop in all <Translator> and <Translate> components within the app.
*Type:* React hook
*Params:*
- `from`
- [`from`](#props) *required*
## Hook `setLanguageTo(to)` ###
### Hook `setLanguageTo(to)` ###
Overrides `to` prop in all <Translator> and <Translate> components within the app.
*Type:* React hook
*Params:*
- `to`
- [`to`](#props) *required*
## Hook `translate(text, from, to)` ###
### Hook `translate(text, from, to)` ###
Translates text and returns translation.
*Type:* Function
*Returns*: string
*Params:*
- `text`: *Type string* *required*
- `from`
- `to`
- `text`: *Type string*, *required*
- [`from`](#props)
- [`to`](#props)

0 comments on commit db654f7

Please sign in to comment.