Import stubs
This commit is contained in:
parent
96c6c4ad1a
commit
67f906ab24
@ -21,20 +21,32 @@ class Dictionary {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.termDicts = {};
|
this.termDicts = {};
|
||||||
this.kanjiDicts = {};
|
this.kanjiDicts = {};
|
||||||
|
this.db = new Dexie('dict');
|
||||||
|
this.dbVer = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTermDict(name, dict) {
|
loadDb() {
|
||||||
|
return this.db.open().then((db) => {
|
||||||
|
if (db.verno !== this.dbVer) {
|
||||||
|
Promise.reject('db version mismatch');
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.verno;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
importTermDict(name, dict) {
|
||||||
this.termDicts[name] = dict;
|
this.termDicts[name] = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
addKanjiDict(name, dict) {
|
importKanjiDict(name, dict) {
|
||||||
this.kanjiDicts[name] = dict;
|
this.kanjiDicts[name] = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
findTerm(term) {
|
findTerm(term) {
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
||||||
for (let name in this.termDicts) {
|
for (const name in this.termDicts) {
|
||||||
const dict = this.termDicts[name];
|
const dict = this.termDicts[name];
|
||||||
if (!(term in dict.i)) {
|
if (!(term in dict.i)) {
|
||||||
continue;
|
continue;
|
||||||
@ -62,7 +74,7 @@ class Dictionary {
|
|||||||
findKanji(kanji) {
|
findKanji(kanji) {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (let name in this.kanjiDicts) {
|
for (const name in this.kanjiDicts) {
|
||||||
const def = this.kanjiDicts[name].c[kanji];
|
const def = this.kanjiDicts[name].c[kanji];
|
||||||
if (def) {
|
if (def) {
|
||||||
const [k, o, t, ...g] = def;
|
const [k, o, t, ...g] = def;
|
||||||
|
@ -31,28 +31,25 @@ class Translator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Translator.loadData('bg/data/rules.json')
|
Translator.loadData('bg/data/rules.json').then((response) => {
|
||||||
.then((response) => {
|
|
||||||
this.deinflector.setRules(JSON.parse(response));
|
this.deinflector.setRules(JSON.parse(response));
|
||||||
return Translator.loadData('bg/data/tags.json');
|
return Translator.loadData('bg/data/tags.json');
|
||||||
})
|
}).then((response) => {
|
||||||
.then((response) => {
|
|
||||||
this.tagMeta = JSON.parse(response);
|
this.tagMeta = JSON.parse(response);
|
||||||
|
return this.dictionary.loadDb();
|
||||||
|
}).then(() => {
|
||||||
|
this.loaded = true;
|
||||||
|
callback();
|
||||||
|
}).catch(() => {
|
||||||
return Translator.loadData('bg/data/edict.json');
|
return Translator.loadData('bg/data/edict.json');
|
||||||
})
|
}).then((response) => {
|
||||||
.then((response) => {
|
this.dictionary.importTermDict('edict', JSON.parse(response));
|
||||||
this.dictionary.addTermDict('edict', JSON.parse(response));
|
return Translator.loadData('bg/data/enamdict.json');
|
||||||
|
}).then((response) => {
|
||||||
|
this.dictionary.importTermDict('enamdict', JSON.parse(response));
|
||||||
return Translator.loadData('bg/data/kanjidic.json');
|
return Translator.loadData('bg/data/kanjidic.json');
|
||||||
})
|
}).then((response) => {
|
||||||
.then((response) => {
|
this.dictionary.importKanjiDict('kanjidic', JSON.parse(response));
|
||||||
this.dictionary.addKanjiDict('kanjidic', JSON.parse(response));
|
|
||||||
return loadEnamDict ? Translator.loadData('bg/data/enamdict.json') : Promise.resolve(null);
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
if (response !== null) {
|
|
||||||
this.dictionary.addTermDict('enamdict', JSON.parse(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user