Migrate to using a loader method

This moves all locale/translation building to a dependency, `scratch-www-intl-loader`, as well as tests associated with it. Also gets rid of the `make translations` step.
This commit is contained in:
Matthew Taylor 2016-01-07 16:59:51 -05:00
parent d5ffd9fcc0
commit 214430b0c4
24 changed files with 88 additions and 399 deletions
src/lib

View file

@ -3,22 +3,21 @@ var ReactDOM = require('react-dom');
var ReactIntl = require('./intl.jsx');
var IntlProvider = ReactIntl.IntlProvider;
var render = function (jsx, element) {
var render = function (jsx, element, messages) {
// Get locale and messages from global namespace (see "init.js")
var locale = window._locale || 'en';
if (typeof window._messages[locale] === 'undefined') {
if (typeof messages[locale] === 'undefined') {
// Fall back on the split
locale = locale.split('-')[0];
}
if (typeof window._messages[locale] === 'undefined') {
if (typeof messages[locale] === 'undefined') {
// Language appears to not be supported fall back to 'en'
locale = 'en';
}
var messages = window._messages[locale];
// Render component
var component = ReactDOM.render(
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages[locale]}>
{jsx}
</IntlProvider>,
element