From 6add4f0916be4c08714acdbd4fdb482123de952d Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Sun, 5 Nov 2017 16:58:41 +0100 Subject: [PATCH] [TASK] Wait for loaded language --- lib/linklist.js | 2 +- lib/main.js | 15 +++++++++++++++ lib/proportions.js | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/linklist.js b/lib/linklist.js index 20cc364..5e77348 100644 --- a/lib/linklist.js +++ b/lib/linklist.js @@ -1,5 +1,6 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) { 'use strict'; + V = V.default; function linkName(d) { return (d.source ? d.source.hostname : d.source.id) + ' – ' + d.target.hostname; @@ -30,7 +31,6 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) { return function (linkScale) { var table = new SortTable(headings, 2, renderRow); - V = V.default; function renderRow(d) { var td1Content = [V.h('a', { diff --git a/lib/main.js b/lib/main.js index bcd9a8b..b0b0fc8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -87,6 +87,21 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], } update() + .then(function (d) { + return new Promise(function (resolve, reject) { + var count = 0; + (function waitForLanguage() { + if (Object.keys(_.phrases).length > 0) { + resolve(d); + } else if (count > 500) { + reject(new Error('translation not loaded after 10 seconds')); + } else { + setTimeout(waitForLanguage.bind(this), 20); + } + count++; + })(); + }); + }) .then(function (d) { var gui = new GUI(language); gui.setData(d); diff --git a/lib/proportions.js b/lib/proportions.js index 44afa8e..0176564 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -1,11 +1,11 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'], function (d3Interpolate, V, Filter, helper) { 'use strict'; + V = V.default; return function (filterManager) { var self = this; var scale = d3Interpolate.interpolate('#770038', '#dc0067'); - V = V.default; var statusTable; var fwTable;