# redux-lexicon

> React / Redux localization tool

Latest version **0.8.0** (published 2017-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-lexicon
pnpm add redux-lexicon
yarn add redux-lexicon
bun add redux-lexicon
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2017-09-29 |
| First published | 2017-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Anton Mamrashev |
| Maintainers | me6iaton |
| Keywords | locale, globalization, localization, translate, translation, redux, react, component |

## Links

- npm: https://www.npmjs.com/package/redux-lexicon
- Repository: https://github.com/me6iaton/redux-lexicon
- Homepage: https://github.com/me6iaton/redux-lexicon#readme
- Issues: https://github.com/me6iaton/redux-lexicon/issues
- npm.io page: https://npm.io/package/redux-lexicon

## Dependencies (3)

- [react](https://npm.io/package/react.md) 15.x
- [prop-types](https://npm.io/package/prop-types.md) 15.x
- [react-redux](https://npm.io/package/react-redux.md) 5.x

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.8.0 (latest) — 2017-09-29
- 0.7.0 — 2017-05-03
- 0.6.0 — 2017-04-28
- 0.5.2 — 2017-04-28
- 0.5.1 — 2017-04-27
- 0.5.0 — 2017-04-27
- 0.4.9 — 2017-04-25
- 0.4.8 — 2017-04-25
- 0.4.7 — 2017-04-25
- 0.4.6 — 2017-04-21
- 0.4.5 — 2017-04-21
- 0.4.4 — 2017-04-21
- 0.4.3 — 2017-04-21
- 0.4.2 — 2017-04-21
- 0.4.1 — 2017-04-21
- … 4 more at https://npm.io/package/redux-lexicon/versions

## README

# redux-lexicon

React / Redux localization tool


## Installation

```
npm install redux-lexicon --save
```

## Api

#### reducer

currentLang reducer

#### setLang

update currentLang action creator

#### withLexContext( mapStateToLang, mapStateToLexicon, defLang = 'en' )( WrappedComponent )

HOC - add lexicon context to App component </br>
mapStateToLang - currentLang selector </br>
mapStateToLexicon - lexicon selector
defLang - default lang

#### withLex( [componentKey] )(WrappedComponent)

HOC - add lex prop to WrappedComponent </br>
componentKey - optional, get only componentKey fields from lexicon

```javascript
withLex()(YouCmp)
withLex('YouCmp')(YouCmp)
withLex('YouCmp', 'OtherCmp')(YouComp)
withLex('YouCmp', 'FerstCmp', 'SecondCmp')(YouComp)
```

## Usage

1. connect lexicon and currentLang reducers to redux store

  You can take currentLang reducer and setLang action from this package

  #### data format from lexicon reducer:

  ```
  {
    en: {
      component1: {
        key1: "en translate",
        key2: "en translate"
      },
      component2: {
        key1: "en translate"
      }
    },
    ru: {
      component1: {
        key1: "ru translate",
        key2: "ru translate"
      },
      component2: {
        key1: " ru translate"
      }
    }
  }
  ```

2. wrap you root component withLexContext

  ```javascript
  import { withLexContext } from 'redux-lexicon'

  class App extends Component {
    ...
  }

  const enhanceLexContext = withLexContext(
    state => state.lang,
    state => state.lexicon
  )
  export default enhanceLexContext(App)
  ```

3. wrap you translate component withLex

  ```javascript
  import { withLex } from 'redux-lexicon'

  class YouComponent extends Component {
    ...
  }

  const enhanceLex = withLex('youComponent')
  export default enhanceLex(YouComponent)
  ```

4. get translate strings from lex prop in YouComponent

---
_Source: https://npm.io/package/redux-lexicon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
