diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-04-18 19:38:03 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-04-18 19:38:03 -0700 |
commit | c4e35fbf54a9cd80e27d600d47b24b1afdfeca6d (patch) | |
tree | ab215a66592e3ec41ce6f2c1a21b64dbda5a9df3 /ext/bg/js/translator.js | |
parent | f8d2cc1b0369e6350a91d540ef6165cd7dc50040 (diff) |
Display tooltips for tags
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1a024a40..e2d15e46 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -19,14 +19,16 @@ class Translator { constructor() { - this.loaded = false; - this.paths = { + this.paths = { rules: 'bg/data/rules.json', + tags: 'bg/data/tags.json', edict: 'bg/data/edict.json', enamdict: 'bg/data/enamdict.json', kanjidic: 'bg/data/kanjidic.json' }; + this.loaded = false; + this.tags = null; this.dictionary = new Dictionary(); this.deinflector = new Deinflector(); } @@ -38,13 +40,16 @@ class Translator { } const pendingLoads = []; - for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) { + for (const key of ['rules', 'tags', 'edict', 'enamdict', 'kanjidic']) { pendingLoads.push(key); Translator.loadData(this.paths[key], (response) => { switch (key) { case 'rules': this.deinflector.setRules(JSON.parse(response)); break; + case 'tags': + this.tags = JSON.parse(response); + break; case 'kanjidic': this.dictionary.addKanjiDict(key, JSON.parse(response)); break; @@ -98,8 +103,8 @@ class Translator { return 1; } - const p1 = v1.tags.indexOf('P') >= 0; - const p2 = v2.tags.indexOf('P') >= 0; + const p1 = v1.tags.hasOwnProperty('P'); + const p2 = v2.tags.hasOwnProperty('P'); if (p1 && !p2) { return -1; } else if (!p1 && p2) { @@ -153,12 +158,20 @@ class Translator { } } + let tagInfo = {}; + for (const tag of entry.tags) { + const info = this.tags[tag]; + if (info) { + tagInfo[tag] = info; + } + } + if (matched) { groups[entry.id] = { expression: entry.expression, reading: entry.reading, glossary: entry.glossary, - tags: entry.tags, + tags: tagInfo, source: source, rules: rules }; |