ndla-i18n
NDLA's own i18n package based on react-intl
Installation
$ npm install ndla-i18n --save
$ yarn add ndla-i18n
Usage
import IntlProvider from '@ndla/i18n';
...
ReactDOM.render(
...
<IntlProvider locale="NB" messages={messages}>
...
</IntlProvider>
...
document.getElementById('root'),
);
...
import { injectT } from '@ndla/i18n';
class i18nReactComponent extends Component {
...
render() {
const { t } = this.props;
return <button>{t('translationItem.buttonText')}</button>;
}
}
...
export default injectT(i18nReactComponent);
...
import { injectT, tType } from '@ndla/i18n';
interface Props {
prop1: number;
prop2: string;
}
const i18nReactComponent: FC<Props & tType> = ({ t, prop1, prop2 }) => {
...
render() {
return <button>{t('translationItem.buttonText')}</button>;
}
}
...
export default injectT(i18nReactComponent);
...
import { Trans } from '@ndla/i18n';
class i18nReactComponent extends Component {
...
render() {
return(
<Trans>
{({ t }) => (<button>{t('translationItem.buttonText')}</button>)}
</Trans>
)
}
}
...
export default i18nReactComponent;