terra-i18n
Version:
The terra-i18n package provides on-demand internationalization of React components.
31 lines (26 loc) • 677 B
JSX
import React from 'react';
import PropTypes from 'prop-types';
import { IntlProvider } from 'react-intl';
const propTypes = {
/**
* The component that will be wrapped by i18n provider.
*/
children: PropTypes.node.isRequired,
/**
* The locale name.
*/
locale: PropTypes.string.isRequired,
/**
* Translations messages object.
*/
messages: PropTypes.shape({}).isRequired,
};
const I18nProvider = ({ children, locale, messages }) => (
<IntlProvider locale={locale} key={locale} messages={messages}>
<React.Fragment>
{children}
</React.Fragment>
</IntlProvider>
);
I18nProvider.propTypes = propTypes;
export default I18nProvider;