aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/translator.js')
-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) => {