content: import React, { Component } from 'react';
  import PropTypes from 'prop-types';
  import { connect } from 'react-redux';
  import { IntlProvider, injectIntl } from 'react-intl';
  
  import config from 'App/config';
  
  const intl = {};
  
  if (process.env.NODE_ENV === 'test') {
    // mock for jest, will be removed in prod build by uglifyjs
    Object.assign(intl, {
      formatMessage: () => 'Error generic',
      // add more if needed
    });
  }
  
  function processLanguage(localStorageLanguage) {
    let language = localStorageLanguage || config.language.app;
    language = config.language.available.includes(language) ? language : config.language.default;
    return language;
  }
  
  const loadLocaleData = language => [
    import(
      /* webpackChunkName: "language-message-data-[request]" */
      /* webpackInclude: /\/(en|pl).json$/ */
      `App/locales/${language}.json` // eslint-disable-line comma-dangle
    ),
    import(
      /* webpackChunkName: "react-intl-locale-data-[request]" */
      /* webpackInclude: /\/(en|pl).js$/ */
      `react-intl/locale-data/${language}.js` // eslint-disable-line comma-dangle
    ),
  ];
  
  class IntlGlobalProvider extends Component {
  
    static propTypes = {
      children: PropTypes.node.isRequired,
      intl: PropTypes.shape().isRequired,
    };
  
    constructor(props) {
      super(props);
      const { intl: intlProp } = this.props;
      Object.assign(intl, intlProp);
    }
  
    render() {
      const { children } = this.props;
      return children;
    }
  
  }
  
  const IntlGlobalProviderInjected = injectIntl(IntlGlobalProvider);
  
  const IntlProviderCustomPure = ({ children, ...rest }) => (
    <IntlProvider {...rest}>
      <IntlGlobalProviderInjected>
        {children}
      </IntlGlobalProviderInjected>
    </IntlProvider>
  );
  
  IntlProviderCustomPure.propTypes = {
    children: PropTypes.node.isRequired,
  };
  
  const mapStateToProps = ({ app }) => {
    const language = app.get('language');
    return {
      locale: language,
      key: language,
      messages: config.language.cache.messageData[language],
    };
  };
  
  const IntlProviderCustom = connect(mapStateToProps)(IntlProviderCustomPure);
  
  export {
    processLanguage,
    loadLocaleData,
    IntlProviderCustom,
    intl,
  };
  