summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-13 16:42:04 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-13 16:42:04 -0700
commit13961e6a10554fdc43c5b1b66f28ea72d2fc21b6 (patch)
tree1ceb76cf56964188f8d59fecd564a4a1f2b95296 /ext/bg/js/translator.js
parentba8451f429d1055f91f79473f32204efb2c041db (diff)
better tag handling
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index a2322e36..99147618 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -60,7 +60,7 @@ class Translator {
let definitions = [];
for (const deinflection of deinflections) {
for (const definition of deinflection.definitions) {
- const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
+ const tags = await this.buildTags(definition.tags, titles);
tags.push(dictTagBuildSource(definition.dictionary));
let frequencies = await this.database.findTermFreq(definition.expression, titles);
@@ -124,12 +124,29 @@ class Translator {
}
for (const definition of definitions) {
- const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
+ const tags = await this.buildTags(definition.tags, titles);
tags.push(dictTagBuildSource(definition.dictionary));
+
definition.tags = dictTagsSort(tags);
definition.frequencies = await this.database.findKanjiFreq(definition.character, titles);
}
return definitions;
}
+
+ async buildTags(names, titles) {
+ const results = [];
+ for (const name of names) {
+ const meta = await this.database.findTag(name.split(':')[0], titles);
+
+ const result = {name};
+ for (const prop in meta || {}) {
+ result[prop] = meta[prop];
+ }
+
+ results.push(dictTagSanitize(result));
+ }
+
+ return results;
+ }
}