2015-10-15 23:11:09 -04:00
|
|
|
|
var ReactDOM = require('react-dom');
|
2015-12-16 12:00:42 -05:00
|
|
|
|
|
|
|
|
|
var ReactIntl = require('./intl.jsx');
|
2015-10-15 23:11:09 -04:00
|
|
|
|
var IntlProvider = ReactIntl.IntlProvider;
|
|
|
|
|
|
2016-01-07 16:59:51 -05:00
|
|
|
|
var render = function (jsx, element, messages) {
|
2015-10-15 23:11:09 -04:00
|
|
|
|
// Get locale and messages from global namespace (see "init.js")
|
2016-01-06 14:09:32 -05:00
|
|
|
|
var locale = window._locale || 'en';
|
2016-01-07 16:59:51 -05:00
|
|
|
|
if (typeof messages[locale] === 'undefined') {
|
2016-01-06 14:09:32 -05:00
|
|
|
|
// Fall back on the split
|
|
|
|
|
locale = locale.split('-')[0];
|
|
|
|
|
}
|
2016-01-07 16:59:51 -05:00
|
|
|
|
if (typeof messages[locale] === 'undefined') {
|
2016-01-06 14:09:32 -05:00
|
|
|
|
// Language appears to not be supported – fall back to 'en'
|
|
|
|
|
locale = 'en';
|
|
|
|
|
}
|
2015-10-15 23:11:09 -04:00
|
|
|
|
|
|
|
|
|
// Render component
|
|
|
|
|
var component = ReactDOM.render(
|
2016-01-07 16:59:51 -05:00
|
|
|
|
<IntlProvider locale={locale} messages={messages[locale]}>
|
2015-10-15 23:11:09 -04:00
|
|
|
|
{jsx}
|
|
|
|
|
</IntlProvider>,
|
|
|
|
|
element
|
|
|
|
|
);
|
|
|
|
|
|
2015-11-03 10:49:32 -05:00
|
|
|
|
// Provide list of rendered components
|
|
|
|
|
window._renderedComponents = window._renderedComponents || [];
|
|
|
|
|
window._renderedComponents.push(component);
|
2015-10-15 23:11:09 -04:00
|
|
|
|
};
|
2015-10-16 15:10:17 -04:00
|
|
|
|
|
|
|
|
|
module.exports = render;
|