Add callback to ui() that will be called after loadLocale completes

(closes #3550)
This commit is contained in:
Bryan Housel
2016-11-07 17:03:33 -05:00
parent ac3dcdadc8
commit 48621d3155
2 changed files with 19 additions and 8 deletions

View File

@@ -318,16 +318,22 @@ export function coreContext(root) {
return context;
};
context.loadLocale = function(cb) {
context.loadLocale = function(callback) {
if (locale && locale !== 'en' && dataLocales.indexOf(locale) !== -1) {
localePath = localePath || context.asset('locales/' + locale + '.json');
d3.json(localePath, function(err, result) {
addTranslation(locale, result[locale]);
setLocale(locale);
cb();
if (!err) {
addTranslation(locale, result[locale]);
setLocale(locale);
}
if (callback) {
callback(err);
}
});
} else {
cb();
if (callback) {
callback();
}
}
};

View File

@@ -284,11 +284,16 @@ export function uiInit(context) {
}
function ui(node) {
function ui(node, callback) {
var container = d3.select(node);
context.container(container);
context.loadLocale(function() {
render(container);
context.loadLocale(function(err) {
if (!err) {
render(container);
}
if (callback) {
callback(err);
}
});
}