aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-24 22:27:25 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-24 22:27:25 -0500
commita5fc79a7540154f66a06f950c3ad434358b71d03 (patch)
tree66f3e56b36079367a8f8e39bf388657eab7e2d67 /ext
parent8233119eb7b15099da310dbd46f005ee678e42ca (diff)
Create buildKanjiMeta for parity with buildTermMeta
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/translator.js37
1 files changed, 23 insertions, 14 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index ebb02687..dfec54ac 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -412,27 +412,19 @@ class Translator {
definitions.sort((a, b) => a.index - b.index);
}
- const kanjiList2 = [];
for (const definition of definitions) {
- kanjiList2.push(definition.character);
-
const tags = await this.expandTags(definition.tags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary));
+ dictTagsSort(tags);
- definition.tags = dictTagsSort(tags);
- definition.stats = await this.expandStats(definition.stats, definition.dictionary);
- definition.frequencies = [];
- }
+ const stats = await this.expandStats(definition.stats, definition.dictionary);
- const metas = await this.database.findKanjiMetaBulk(kanjiList2, titles);
- for (const {character, mode, data, dictionary, index} of metas) {
- switch (mode) {
- case 'freq':
- definitions[index].frequencies.push({character, frequency: data, dictionary});
- break;
- }
+ definition.tags = tags;
+ definition.stats = stats;
}
+ await this.buildKanjiMeta(definitions, titles);
+
return definitions;
}
@@ -482,6 +474,23 @@ class Translator {
}
}
+ async buildKanjiMeta(definitions, titles) {
+ const kanjiList = [];
+ for (const definition of definitions) {
+ kanjiList.push(definition.character);
+ definition.frequencies = [];
+ }
+
+ const metas = await this.database.findKanjiMetaBulk(kanjiList, titles);
+ for (const {character, mode, data, dictionary, index} of metas) {
+ switch (mode) {
+ case 'freq':
+ definitions[index].frequencies.push({character, frequency: data, dictionary});
+ break;
+ }
+ }
+ }
+
async expandTags(names, title) {
const tagMetaList = await this.getTagMetaList(names, title);
return tagMetaList.map((meta, index) => {