mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
5705f72fb8
* fix: make sure en|ru locale import after zh-CN * refactor: simplify code
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import { addLocaleData, IntlProvider } from 'react-intl';
|
|
import { LocaleProvider } from 'antd';
|
|
import enUS from 'antd/lib/locale-provider/en_US';
|
|
import Header from './Header';
|
|
import Footer from './Footer';
|
|
import enLocale from '../../en-US';
|
|
import cnLocale from '../../zh-CN';
|
|
import '../../static/style';
|
|
|
|
// Expose to iframe
|
|
window.react = React;
|
|
window['react-dom'] = ReactDOM;
|
|
window.antd = require('antd');
|
|
|
|
const language = (typeof localStorage === 'undefined' || !localStorage.getItem('locale')) ?
|
|
navigator.language : localStorage.getItem('locale');
|
|
const isZhCN = language === 'zh-CN';
|
|
|
|
const appLocale = isZhCN ? cnLocale : enLocale;
|
|
addLocaleData(appLocale.data);
|
|
|
|
export default class Layout extends React.Component {
|
|
static contextTypes = {
|
|
router: React.PropTypes.object.isRequired,
|
|
}
|
|
|
|
componentDidMount() {
|
|
if (typeof ga !== 'undefined') {
|
|
this.context.router.listen((loc) => {
|
|
window.ga('send', 'pageview', loc.pathname + loc.search);
|
|
});
|
|
}
|
|
|
|
const loadingNode = document.getElementById('ant-site-loading');
|
|
if (loadingNode) {
|
|
this.timer = setTimeout(() => {
|
|
loadingNode.parentNode.removeChild(loadingNode);
|
|
}, 450);
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearTimeout(this.timer);
|
|
}
|
|
|
|
render() {
|
|
const { children, ...restProps } = this.props;
|
|
return (
|
|
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
|
|
<LocaleProvider locale={enUS}>
|
|
<div className="page-wrapper">
|
|
<Header {...restProps} />
|
|
{children}
|
|
<Footer />
|
|
</div>
|
|
</LocaleProvider>
|
|
</IntlProvider>
|
|
);
|
|
}
|
|
}
|