Vulcan/packages/nova-core/lib/components/App.jsx

50 lines
1.1 KiB
React
Raw Normal View History

2016-12-12 15:10:53 +09:00
import { Components, registerComponent, getSetting, Strings } from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
2016-06-09 20:45:58 +09:00
import { IntlProvider, intlShape} from 'react-intl';
import withCurrentUser from '../containers/withCurrentUser.js';
2016-12-12 15:10:53 +09:00
class App extends Component {
2016-03-24 18:17:35 +09:00
2016-06-09 17:42:20 +09:00
getLocale() {
2016-12-12 15:00:56 +09:00
return getSetting("locale", "en");
2016-06-09 17:42:20 +09:00
}
getChildContext() {
2016-06-09 17:42:20 +09:00
2016-12-12 15:10:53 +09:00
const messages = Strings[this.getLocale()] || {};
2016-06-09 20:45:58 +09:00
const intlProvider = new IntlProvider({locale: this.getLocale()}, messages);
2016-06-09 17:42:20 +09:00
const {intl} = intlProvider.getChildContext();
2016-03-24 18:17:35 +09:00
return {
2016-06-09 17:42:20 +09:00
intl: intl
2016-03-24 18:17:35 +09:00
};
}
render() {
return (
2016-12-12 15:10:53 +09:00
<IntlProvider locale={this.getLocale()} messages={Strings[this.getLocale()]}>
{
this.props.loading ?
<Components.Loading /> :
<Components.Layout>{this.props.children}</Components.Layout>
}
</IntlProvider>
)
}
}
App.propTypes = {
loading: React.PropTypes.bool,
}
App.childContextTypes = {
intl: intlShape,
}
registerComponent('App', App, withCurrentUser);
export default App;