Cleanup
This commit is contained in:
parent
d5ea03171e
commit
8eb43c93d9
@ -25,13 +25,12 @@ class Translator {
|
|||||||
this.deinflector = new Deinflector();
|
this.deinflector = new Deinflector();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData({loadEnamDict=true}, callback) {
|
loadData() {
|
||||||
if (this.loaded) {
|
if (this.loaded) {
|
||||||
callback();
|
return Promise.resolve();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadJson('bg/data/rules.json').then(rules => {
|
return loadJson('bg/data/rules.json').then(rules => {
|
||||||
this.deinflector.setRules(rules);
|
this.deinflector.setRules(rules);
|
||||||
return loadJson('bg/data/tags.json');
|
return loadJson('bg/data/tags.json');
|
||||||
}).then(tagMeta => {
|
}).then(tagMeta => {
|
||||||
@ -39,18 +38,15 @@ class Translator {
|
|||||||
return this.dictionary.existsDb();
|
return this.dictionary.existsDb();
|
||||||
}).then(exists => {
|
}).then(exists => {
|
||||||
this.dictionary.initDb();
|
this.dictionary.initDb();
|
||||||
if (exists) {
|
if (!exists) {
|
||||||
return Promise.resolve();
|
return Promise.all([
|
||||||
|
this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'),
|
||||||
|
this.dictionary.importTermDict('bg/data/edict/index.json'),
|
||||||
|
this.dictionary.importTermDict('bg/data/enamdict/index.json')
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all([
|
|
||||||
this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'),
|
|
||||||
this.dictionary.importTermDict('bg/data/edict/index.json'),
|
|
||||||
this.dictionary.importTermDict('bg/data/enamdict/index.json')
|
|
||||||
]);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
callback();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +190,10 @@ class Translator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processKanji(entries) {
|
processKanji(definitions) {
|
||||||
const results = [];
|
for (const definition of definitions) {
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
const tagItems = [];
|
const tagItems = [];
|
||||||
for (const tag of entry.tags) {
|
for (const tag of definition.tags) {
|
||||||
const tagItem = {
|
const tagItem = {
|
||||||
name: tag,
|
name: tag,
|
||||||
class: 'default',
|
class: 'default',
|
||||||
@ -211,16 +205,10 @@ class Translator {
|
|||||||
tagItems.push(tagItem);
|
tagItems.push(tagItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push({
|
definition.tags = Translator.sortTags(tagItems);
|
||||||
character: entry.character,
|
|
||||||
kunyomi: entry.kunyomi,
|
|
||||||
onyomi: entry.onyomi,
|
|
||||||
glossary: entry.glossary,
|
|
||||||
tags: Translator.sortTags(tagItems)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyTagMeta(tag) {
|
applyTagMeta(tag) {
|
||||||
|
@ -101,7 +101,7 @@ class Yomichan {
|
|||||||
break;
|
break;
|
||||||
case 'loading':
|
case 'loading':
|
||||||
chrome.browserAction.setBadgeText({text: '...'});
|
chrome.browserAction.setBadgeText({text: '...'});
|
||||||
this.translator.loadData({loadEnamDict: this.options.loadEnamDict}, () => this.setState('enabled'));
|
this.translator.loadData().then(() => this.setState('enabled'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user