diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-09-17 19:16:08 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-09-17 19:16:08 -0700 |
commit | d9d16613f8aa129de5dc1edb38d66f69d2983091 (patch) | |
tree | 3936a737082cde393f92ba54869db10cf90f6f89 /ext/bg/js/translator.js | |
parent | 269a4f0b9ba1876bd5a6e72e34537056a75081fc (diff) |
wip
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 32 |
1 files changed, 27 insertions, 5 deletions
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; + } } |