aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-02 12:56:47 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-02 12:56:47 -0700
commita6fda6c94340c570442fbd20db2ab99a8bbcf289 (patch)
treeb02cda4bd584ae1a70130f9c16ba9848f6dbe0a2 /ext/bg/translator.js
parent036639aeafccfa20db0edd4780abbd391da74922 (diff)
Work with new dictionary format
Diffstat (limited to 'ext/bg/translator.js')
-rw-r--r--ext/bg/translator.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/ext/bg/translator.js b/ext/bg/translator.js
index e76a1b07..23d5d964 100644
--- a/ext/bg/translator.js
+++ b/ext/bg/translator.js
@@ -19,9 +19,9 @@
class Translator {
constructor() {
- this.dictionary = new Dictionary();
- this.deinflector = new Deinflector();
- this.pendingLoads = [];
+ this.dictionary = new Dictionary();
+ this.deinflector = new Deinflector();
+ this.initialized = false;
}
loadData(paths, callback) {
@@ -30,8 +30,9 @@ class Translator {
return;
}
+ const pendingLoads = [];
for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
- this.pendingLoads.push(key);
+ pendingLoads.push(key);
Translator.loadData(paths[key], (response) => {
switch (key) {
case 'rules':
@@ -46,9 +47,9 @@ class Translator {
break;
}
- const index = this.pendingLoads.indexOf(key);
- this.pendingLoads = this.pendingLoads.splice(index, 1);
- if (this.pendingLoads.length === 0) {
+ pendingLoads.splice(pendingLoads.indexOf(key), 1);
+ if (pendingLoads.length === 0) {
+ this.initialized = true;
callback();
}
});
@@ -160,7 +161,9 @@ class Translator {
static parseCsv(data) {
const result = [];
for (const row of data.split('\n')) {
- result.push(row.split('\t'));
+ if (row.length > 0) {
+ result.push(row.split('\t'));
+ }
}
return result;