/react-i18context

simple react intl in 100 lines, https://www.npmjs.com/package/react-i18context

Primary LanguageJavaScript

react-i18context

How to run the demo

npm install
npm run start

How to use this in your project

npm install --save react-i18context

API

1.IntlProvider

// messages is an array object, key is the languae, see the demo
<IntlProvider messages={messages} locale="en">
    <App />
</IntlProvider>

2.FormatMsg

// id is the text you want to translate
<FormatMsg id="test" />

3.LocaleSet

// locale is the language you want to use when you click this button
<LocaleSet locale={lang}>
  <button>change language</button>
</LocaleSet>

4. InjectIntlLangWrapper

// in the FooComponent props will inject the setLocale method, so you can chnage the language manually
InjectIntlLangWrapper(FooComponent)