0.8.0 • Published 7 years ago

redux-lexicon v0.8.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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 mapStateToLang - currentLang selector mapStateToLexicon - lexicon selector defLang - default lang

withLex( componentKey )(WrappedComponent)

HOC - add lex prop to WrappedComponent componentKey - optional, get only componentKey fields from lexicon

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

    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

    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

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago