ampache_react/index.all.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

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";
// 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";
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");
// i18n
export const onWindowIntl = () => {
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
let render = () => {
const Root = require("./app/containers/Root").default;
2016-07-26 15:59:18 +02:00
ReactDOM.render(
<Root store={store} history={history} locale={locale} defaultLocale="en-US" messages={strings} />,
2016-07-26 15:59:18 +02:00
rootElement
);
};
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();
});
} else {
render();
}
};