2016-12-20 13:29:54 +02:00
|
|
|
const React = require('react');
|
|
|
|
const ReactRedux = require('react-redux');
|
|
|
|
const ReactIntl = require('react-intl');
|
2017-02-06 16:51:55 +02:00
|
|
|
const ReactRouter = require('react-router-dom');
|
2017-02-20 18:15:36 +02:00
|
|
|
const createStore = require('@state/store').default;
|
2016-12-20 13:29:54 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
addLocaleData,
|
|
|
|
IntlProvider
|
|
|
|
} = ReactIntl;
|
|
|
|
|
|
|
|
const {
|
|
|
|
Provider
|
|
|
|
} = ReactRedux;
|
|
|
|
|
2016-12-20 21:06:02 +02:00
|
|
|
const {
|
|
|
|
BrowserRouter
|
|
|
|
} = ReactRouter;
|
|
|
|
|
2016-12-20 13:29:54 +02:00
|
|
|
const Messages = {
|
|
|
|
'en-us': require('../../locales/en-us.json'),
|
|
|
|
'pt-pt': require('../../locales/pt-pt.json')
|
|
|
|
};
|
|
|
|
|
|
|
|
const Locales = {
|
|
|
|
'en': require('react-intl/locale-data/en'),
|
|
|
|
'pt': require('react-intl/locale-data/pt')
|
|
|
|
};
|
|
|
|
|
|
|
|
const LocalesMessages = {
|
|
|
|
'en-us': {
|
|
|
|
messages: Messages['en-us'],
|
|
|
|
locale: 'en'
|
|
|
|
},
|
|
|
|
'pt-pt': {
|
|
|
|
messages: Messages['pt-pt'],
|
|
|
|
locale: 'pt'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(Locales).forEach((lang) => {
|
|
|
|
addLocaleData(Locales[lang] || []);
|
|
|
|
});
|
|
|
|
|
|
|
|
const withRedux = (children, {
|
|
|
|
store = createStore()
|
|
|
|
} = {}) => (
|
|
|
|
<Provider store={store}>
|
|
|
|
{children}
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const withIntl = (children, {
|
|
|
|
locale = 'en-us'
|
|
|
|
} = {}) => (
|
|
|
|
<IntlProvider
|
|
|
|
locale={LocalesMessages[locale].locale}
|
|
|
|
messages={LocalesMessages[locale].messages}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</IntlProvider>
|
|
|
|
);
|
|
|
|
|
2016-12-20 21:06:02 +02:00
|
|
|
const withRouter = (children, props = {}) => (
|
|
|
|
<BrowserRouter>
|
|
|
|
{children}
|
|
|
|
</BrowserRouter>
|
|
|
|
);
|
|
|
|
|
2017-02-07 11:55:18 +02:00
|
|
|
module.exports = (children, props) =>
|
|
|
|
withRouter(withRedux(withIntl(children), props));
|
|
|
|
|
2016-12-20 13:29:54 +02:00
|
|
|
module.exports.withIntl = withIntl;
|
2016-12-20 21:06:02 +02:00
|
|
|
module.exports.withRedux = withRedux;
|
|
|
|
module.exports.withRouter = withRouter;
|