ndla-i18n

0.3.3 • Public • Published

ndla-i18n

NDLA's own i18n package based on react-intl

Installation

# Using npm: 
$ npm install ndla-i18n --save
 
# Using yarn: 
$ yarn add ndla-i18n

Usage

// In app/server entry index file:
import IntlProvider from 'ndla-i18n';
...
ReactDOM.render(
  ...
    <IntlProvider locale="NB" messages={messages}>
      ...
    </IntlProvider>
  ...
  document.getElementById('root'),
);
// After initial instantiation, using it with a React component
...
import { injectT } from 'ndla-i18n';
 
class i18nReactComponent extends Component {
  ...
  render() {
    const { t } = this.props;
    return <button>{t('translationItem.buttonText')}</button>;
  }
}
...
 
export default injectT(i18nReactComponent);
// Using it with a render props component
...
import { Trans } from 'ndla-i18n';
 
class i18nReactComponent extends Component {
  ...
  render() {
    return(
      <Trans>
      {({ t }) => (<button>{t('translationItem.buttonText')}</button>)}
      </Trans>
    )
  }
}
...
 
export default i18nReactComponent;

Dependents (0)

Package Sidebar

Install

npm i ndla-i18n

Weekly Downloads

0

Version

0.3.3

License

GPL-3.0

Unpacked Size

27.2 kB

Total Files

17

Last publish

Collaborators

  • chrpeter
  • kodevil
  • ndla
  • oyvinmar
  • sebastianjg