2016-07-26 13:21:37 +02:00
|
|
|
// Handle app init
|
|
|
|
import React from "react";
|
2016-07-26 15:59:18 +02:00
|
|
|
import ReactDOM from "react-dom";
|
2016-07-26 13:21:37 +02:00
|
|
|
import { hashHistory } from "react-router";
|
|
|
|
import { syncHistoryWithStore } from "react-router-redux";
|
|
|
|
|
2016-07-28 01:22:48 +02:00
|
|
|
// i18n
|
|
|
|
import { addLocaleData } from "react-intl";
|
|
|
|
import en from "react-intl/locale-data/en";
|
|
|
|
import fr from "react-intl/locale-data/fr";
|
|
|
|
|
2016-07-26 13:21:37 +02:00
|
|
|
import configureStore from "./app/store/configureStore";
|
|
|
|
|
2016-07-28 01:22:48 +02:00
|
|
|
import { getBrowserLocale } from "./app/utils";
|
|
|
|
import rawMessages from "./app/locales";
|
|
|
|
|
2016-07-26 13:21:37 +02:00
|
|
|
const store = configureStore();
|
|
|
|
const history = syncHistoryWithStore(hashHistory, store);
|
|
|
|
|
2016-07-26 15:59:18 +02:00
|
|
|
const rootElement = document.getElementById("root");
|
|
|
|
|
2016-07-28 01:22:48 +02:00
|
|
|
// i18n
|
2016-07-28 23:14:52 +02:00
|
|
|
export const onWindowIntl = () => {
|
2016-07-28 01:22:48 +02:00
|
|
|
addLocaleData([...en, ...fr]);
|
|
|
|
const locale = getBrowserLocale();
|
|
|
|
var strings = rawMessages[locale] ? rawMessages[locale] : rawMessages["en-US"];
|
|
|
|
strings = Object.assign(rawMessages["en-US"], strings);
|
2016-07-26 15:59:18 +02:00
|
|
|
|
2016-07-28 01:22:48 +02:00
|
|
|
let render = () => {
|
|
|
|
const Root = require("./app/containers/Root").default;
|
2016-07-26 15:59:18 +02:00
|
|
|
ReactDOM.render(
|
2016-07-28 01:22:48 +02:00
|
|
|
<Root store={store} history={history} locale={locale} defaultLocale="en-US" messages={strings} />,
|
2016-07-26 15:59:18 +02:00
|
|
|
rootElement
|
|
|
|
);
|
|
|
|
};
|
2016-07-28 01:22:48 +02:00
|
|
|
|
2016-07-28 23:14:52 +02:00
|
|
|
return render;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Intl = (render) => {
|
|
|
|
if (!window.Intl) {
|
|
|
|
require.ensure([
|
|
|
|
"intl",
|
|
|
|
"intl/locale-data/jsonp/en.js",
|
|
|
|
"intl/locale-data/jsonp/fr.js"
|
|
|
|
], function (require) {
|
|
|
|
require("intl");
|
|
|
|
require("intl/locale-data/jsonp/en.js");
|
|
|
|
require("intl/locale-data/jsonp/fr.js");
|
|
|
|
render();
|
2016-07-28 01:22:48 +02:00
|
|
|
});
|
2016-07-28 23:14:52 +02:00
|
|
|
} else {
|
|
|
|
render();
|
2016-07-28 01:22:48 +02:00
|
|
|
}
|
|
|
|
};
|