mirror of
https://github.com/strapi/strapi.git
synced 2025-08-05 15:29:04 +00:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
/*
|
|
*
|
|
* LanguageProvider
|
|
*
|
|
* this component connects the redux state language locale to the
|
|
* IntlProvider component and i18n messages (loaded from `app/translations`)
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { createSelector } from 'reselect';
|
|
import { IntlProvider } from 'react-intl';
|
|
import { selectLocale } from './selectors';
|
|
|
|
export class LanguageProvider extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
render() {
|
|
return (
|
|
<IntlProvider locale={this.props.locale} messages={this.props.messages[this.props.locale]}>
|
|
{React.Children.only(this.props.children)}
|
|
</IntlProvider>
|
|
);
|
|
}
|
|
}
|
|
|
|
LanguageProvider.propTypes = {
|
|
locale: React.PropTypes.string,
|
|
messages: React.PropTypes.object,
|
|
children: React.PropTypes.element.isRequired,
|
|
};
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
selectLocale(),
|
|
(locale) => ({ locale })
|
|
);
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
return {
|
|
dispatch,
|
|
};
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LanguageProvider);
|