aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-03 22:22:38 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-03 22:22:38 -0700
commit44d2b5ec562febc2582bdd93f7f503a92099253f (patch)
tree64afdb21e4f606d5596212f9c82f6ae5be1ef485 /ext/bg/translator.js
parentaef347c67c2380614606296eb2ace6a40f3bd8a8 (diff)
Refactor
Diffstat (limited to 'ext/bg/translator.js')
-rw-r--r--ext/bg/translator.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/bg/translator.js b/ext/bg/translator.js
index 23d5d964..e8224320 100644
--- a/ext/bg/translator.js
+++ b/ext/bg/translator.js
@@ -19,13 +19,20 @@
class Translator {
constructor() {
+ this.loaded = false;
+ this.paths = {
+ rules: 'bg/data/rules.json',
+ edict: 'bg/data/edict.csv',
+ enamdict: 'bg/data/enamdict.csv',
+ kanjidic: 'bg/data/kanjidic.csv'
+ };
+
this.dictionary = new Dictionary();
this.deinflector = new Deinflector();
- this.initialized = false;
}
- loadData(paths, callback) {
- if (this.initialized) {
+ loadData(callback) {
+ if (this.loaded) {
callback();
return;
}
@@ -33,7 +40,7 @@ class Translator {
const pendingLoads = [];
for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
pendingLoads.push(key);
- Translator.loadData(paths[key], (response) => {
+ Translator.loadData(this.paths[key], (response) => {
switch (key) {
case 'rules':
this.deinflector.setRules(JSON.parse(response));
@@ -49,7 +56,7 @@ class Translator {
pendingLoads.splice(pendingLoads.indexOf(key), 1);
if (pendingLoads.length === 0) {
- this.initialized = true;
+ this.loaded = true;
callback();
}
});