Renaming things
This commit is contained in:
parent
c11b24cb37
commit
a18f3be559
@ -9,7 +9,7 @@
|
|||||||
<script src="js/ankinull.js"></script>
|
<script src="js/ankinull.js"></script>
|
||||||
<script src="js/templates.js"></script>
|
<script src="js/templates.js"></script>
|
||||||
<script src="js/util.js"></script>
|
<script src="js/util.js"></script>
|
||||||
<script src="js/dictionary.js"></script>
|
<script src="js/database.js"></script>
|
||||||
<script src="js/deinflector.js"></script>
|
<script src="js/deinflector.js"></script>
|
||||||
<script src="js/translator.js"></script>
|
<script src="js/translator.js"></script>
|
||||||
<script src="js/options.js"></script>
|
<script src="js/options.js"></script>
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class Dictionary {
|
class Database {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = null;
|
this.db = null;
|
||||||
this.dbVer = 6;
|
this.dbVer = 6;
|
||||||
this.entities = null;
|
this.entities = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
initDb() {
|
init() {
|
||||||
if (this.db !== null) {
|
if (this.db !== null) {
|
||||||
return Promise.reject('database already initialized');
|
return Promise.reject('database already initialized');
|
||||||
}
|
}
|
||||||
@ -39,8 +39,8 @@ class Dictionary {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDb() {
|
prepare() {
|
||||||
this.initDb();
|
this.init();
|
||||||
|
|
||||||
return this.db.meta.get('version').then(row => {
|
return this.db.meta.get('version').then(row => {
|
||||||
return row ? row.value : 0;
|
return row ? row.value : 0;
|
||||||
@ -56,13 +56,13 @@ class Dictionary {
|
|||||||
this.db = null;
|
this.db = null;
|
||||||
|
|
||||||
return db.delete().then(() => {
|
return db.delete().then(() => {
|
||||||
this.initDb();
|
this.init();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sealDb() {
|
seal() {
|
||||||
if (this.db === null) {
|
if (this.db === null) {
|
||||||
return Promise.reject('database not initialized');
|
return Promise.reject('database not initialized');
|
||||||
}
|
}
|
@ -166,7 +166,7 @@ function populateDictionaries(opts) {
|
|||||||
const container = $('.dicts');
|
const container = $('.dicts');
|
||||||
container.empty();
|
container.empty();
|
||||||
|
|
||||||
yomichan().translator.dictionary.getDictionaries().then(rows => {
|
yomichan().translator.database.getDictionaries().then(rows => {
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false};
|
const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false};
|
||||||
const html = Handlebars.templates['dictionary.html']({
|
const html = Handlebars.templates['dictionary.html']({
|
||||||
@ -184,7 +184,7 @@ function populateDictionaries(opts) {
|
|||||||
$('.dict-delete').click(e => {
|
$('.dict-delete').click(e => {
|
||||||
const dict = $(e.target).closest('.dict');
|
const dict = $(e.target).closest('.dict');
|
||||||
const title = dict.data('title');
|
const title = dict.data('title');
|
||||||
yomichan().translator.dictionary.deleteDictionary(title);
|
yomichan().translator.database.deleteDictionary(title);
|
||||||
dict.slideUp();
|
dict.slideUp();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class Translator {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
this.tagMeta = null;
|
this.tagMeta = null;
|
||||||
this.dictionary = new Dictionary();
|
this.database = new Database();
|
||||||
this.deinflector = new Deinflector();
|
this.deinflector = new Deinflector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class Translator {
|
|||||||
return loadJson('bg/data/tags.json');
|
return loadJson('bg/data/tags.json');
|
||||||
}).then(tagMeta => {
|
}).then(tagMeta => {
|
||||||
this.tagMeta = tagMeta;
|
this.tagMeta = tagMeta;
|
||||||
return this.dictionary.prepareDb();
|
return this.database.prepare();
|
||||||
}).then(exists => {
|
}).then(exists => {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return;
|
return;
|
||||||
@ -62,11 +62,11 @@ class Translator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.dictionary.importDictionary('bg/data/edict/index.json', bankCallback),
|
this.database.importDictionary('bg/data/edict/index.json', bankCallback),
|
||||||
this.dictionary.importDictionary('bg/data/enamdict/index.json', bankCallback),
|
this.database.importDictionary('bg/data/enamdict/index.json', bankCallback),
|
||||||
this.dictionary.importDictionary('bg/data/kanjidic/index.json', bankCallback),
|
this.database.importDictionary('bg/data/kanjidic/index.json', bankCallback),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
return this.dictionary.sealDb();
|
return this.database.seal();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({state: 'end', progress: 100.0});
|
callback({state: 'end', progress: 100.0});
|
||||||
@ -84,7 +84,7 @@ class Translator {
|
|||||||
for (let i = text.length; i > 0; --i) {
|
for (let i = text.length; i > 0; --i) {
|
||||||
deinflectPromises.push(
|
deinflectPromises.push(
|
||||||
this.deinflector.deinflect(text.slice(0, i), term => {
|
this.deinflector.deinflect(text.slice(0, i), term => {
|
||||||
return this.dictionary.findTerm(term).then(definitions => definitions.map(definition => definition.tags));
|
return this.database.findTerm(term).then(definitions => definitions.map(definition => definition.tags));
|
||||||
}).then(deinflects => {
|
}).then(deinflects => {
|
||||||
const processPromises = [];
|
const processPromises = [];
|
||||||
for (const deinflect of deinflects) {
|
for (const deinflect of deinflects) {
|
||||||
@ -143,7 +143,7 @@ class Translator {
|
|||||||
|
|
||||||
for (const c of text) {
|
for (const c of text) {
|
||||||
if (!processed[c]) {
|
if (!processed[c]) {
|
||||||
promises.push(this.dictionary.findKanji(c).then((definitions) => definitions));
|
promises.push(this.database.findKanji(c).then((definitions) => definitions));
|
||||||
processed[c] = true;
|
processed[c] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processTerm(groups, source, tags, rules, root) {
|
processTerm(groups, source, tags, rules, root) {
|
||||||
return this.dictionary.findTerm(root).then(definitions => {
|
return this.database.findTerm(root).then(definitions => {
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
if (definition.id in groups) {
|
if (definition.id in groups) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user