aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-08-23 20:33:04 -0700
committerAlex Yatskov <alex@foosoft.net>2016-08-23 20:33:04 -0700
commitf106b64876c975237e8c8bb51518ab53d2a9d2fc (patch)
tree6a2a2c5a5798753b9db1f0ab668f606575fa2278 /ext/bg/js/translator.js
parent9621a0cd4b8ea395b78418d2aca210183394f4a4 (diff)
WIP
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js31
1 files changed, 14 insertions, 17 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 75f91055..f9ac1d56 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -36,27 +36,24 @@ class Translator {
return Translator.loadData('bg/data/tags.json');
}).then((response) => {
this.tagMeta = JSON.parse(response);
- return this.dictionary.loadDb();
+ return this.dictionary.existsDb();
+ }).then((exists) => {
+ if (exists) {
+ return this.dictionary.loadDb();
+ } else {
+ this.dictionary.initDb();
+ return Promise.all([
+ this.dictionary.importTermDict('bg/data/edict/index.json'),
+ this.dictionary.importTermDict('bg/data/enamdict/index.json')
+ ]);
+ }
}).then(() => {
this.loaded = true;
callback();
- }).catch(() => {
- return this.dictionary.resetDb().then(() => {
- return Translator.loadData('bg/data/edict.json');
- }).then((response) => {
- return this.dictionary.importTermDict(JSON.parse(response));
- }).then(() => {
- return Translator.loadData('bg/data/enamdict.json');
- }).then((response) => {
- return this.dictionary.importTermDict(JSON.parse(response));
- }).then(() => {
- return Translator.loadData('bg/data/kanjidic.json');
- }).then((response) => {
- return this.dictionary.importKanjiDict(JSON.parse(response));
+
+ this.dictionary.findTerm('猫').then((result) => {
+ console.log(result);
});
- }).then(() => {
- this.loaded = true;
- callback();
});
}