summaryrefslogtreecommitdiff
path: root/ext/bg
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
parent036639aeafccfa20db0edd4780abbd391da74922 (diff)
Work with new dictionary format
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/dictionary.js2
-rw-r--r--ext/bg/translator.js19
2 files changed, 12 insertions, 9 deletions
diff --git a/ext/bg/dictionary.js b/ext/bg/dictionary.js
index 1264263a..a68c2daf 100644
--- a/ext/bg/dictionary.js
+++ b/ext/bg/dictionary.js
@@ -60,7 +60,7 @@ class Dictionary {
storeIndex(indices, term, index) {
if (term.length > 0) {
const indices = this.termIndices[term] || [];
- indices.push(term);
+ indices.push(index);
this.termIndices[term] = indices;
}
}
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;