From d9d16613f8aa129de5dc1edb38d66f69d2983091 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 19:16:08 -0700 Subject: wip --- ext/bg/js/translator.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'ext/bg/js/translator.js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3dd482ca..ef2227ea 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -78,7 +78,7 @@ class Translator { let definitions = []; for (const deinflection of deinflections) { for (const definition of deinflection.definitions) { - const tags = await this.expandTags(definition); + const tags = await this.expandTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); definitions.push({ @@ -136,9 +136,12 @@ class Translator { } for (const definition of definitions) { - const tags = await this.expandTags(definition); + const tags = await this.expandTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); + definition.tags = dictTagsSort(tags); + definition.stats = await this.expandTaggedValues(definition.stats, definition.dictionary); + definition.indices = await this.expandTaggedValues(definition.indices, definition.dictionary); definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } @@ -152,11 +155,11 @@ class Translator { } } - async expandTags(definition) { + async expandTags(names, title) { const tags = []; - for (const name of definition.tags) { + for (const name of names) { const base = name.split(':')[0]; - const meta = await this.database.findTagForTitle(base, definition.dictionary); + const meta = await this.database.findTagForTitle(base, title); const tag = {name}; for (const prop in meta || {}) { @@ -170,4 +173,23 @@ class Translator { return tags; } + + async expandTaggedValues(items, title) { + const tags = []; + for (const name in items) { + const base = name.split(':')[0]; + const meta = await this.database.findTagForTitle(base, title); + + const tag = {name, value: items[name]}; + for (const prop in meta || {}) { + if (prop !== 'name') { + tag[prop] = meta[prop]; + } + } + + tags.push(dictTagSanitize(tag)); + } + + return tags; + } } -- cgit v1.2.3