From 29135ff84ff51dfdbf271490bc53138e306e75d8 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 7 Aug 2016 19:56:50 -0700 Subject: Updating kanji display --- ext/bg/js/dictionary.js | 3 +- ext/bg/js/templates.js | 84 +++++++++++++++++++++---------------------------- ext/bg/js/translator.js | 35 ++++++++++++++++++++- 3 files changed, 71 insertions(+), 51 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index f312796d..a6438523 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -65,11 +65,12 @@ class Dictionary { for (let name in this.kanjiDicts) { const def = this.kanjiDicts[name].c[kanji]; if (def) { - const [k, o, ...g] = def; + const [k, o, t, ...g] = def; results.push({ character: kanji, kunyomi: k.split(' '), onyomi: o.split(' '), + tags: t.split(' '), glossary: g }); } diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index ef26ab81..eec28982 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -37,30 +37,26 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia },"4":function(container,depth0,helpers,partials,data) { var stack1; - return "
Meanings
\n
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n"; -},"5":function(container,depth0,helpers,partials,data) { - var stack1; - - return " " + return " " + container.escapeExpression(container.lambda(depth0, depth0)) - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; -},"6":function(container,depth0,helpers,partials,data) { +},"5":function(container,depth0,helpers,partials,data) { return ", "; -},"8":function(container,depth0,helpers,partials,data) { - var stack1; - - return "
Kun'yomi
\n
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n"; -},"10":function(container,depth0,helpers,partials,data) { - var stack1; +},"7":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; - return "
On'yomi
\n
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n"; + return " " + + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + + "\n"; +},"9":function(container,depth0,helpers,partials,data) { + return "
  • " + + container.escapeExpression(container.lambda(depth0, depth0)) + + "
  • \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; @@ -68,13 +64,15 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["with"].call(alias1,(depth0 != null ? depth0.options : depth0),{"name":"with","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
    " + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) - + "
    \n\n
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(10, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    \n\n"; + + "\n\n
    \n \n \n \n \n \n \n \n \n \n
    Kunyomi:\n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    Onyomi:\n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n\n
    \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n\n
    \n
      \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n\n"; },"useData":true,"useDepths":true}); templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var helper; @@ -146,26 +144,14 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial },"11":function(container,depth0,helpers,partials,data) { var stack1; - return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; -},"12":function(container,depth0,helpers,partials,data) { - var stack1; - return " " + container.escapeExpression(container.lambda(depth0, depth0)) + " " - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; -},"13":function(container,depth0,helpers,partials,data) { +},"12":function(container,depth0,helpers,partials,data) { return "«"; -},"15":function(container,depth0,helpers,partials,data) { - var stack1; - - return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; -},"16":function(container,depth0,helpers,partials,data) { +},"14":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; -},"18":function(container,depth0,helpers,partials,data) { +},"16":function(container,depth0,helpers,partials,data) { return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) + "
  • \n"; @@ -186,12 +172,12 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial + ((stack1 = helpers["with"].call(alias1,(depth0 != null ? depth0.options : depth0),{"name":"with","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0, blockParams, depths),"inverse":container.program(9, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") - + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n
    \n
      \n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(18, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n
      \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
      \n\n
      \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(14, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
      \n\n
      \n
        \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
      \n
      \n
    \n"; },"useData":true,"useDepths":true}); templates['term-list.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index b7fce392..cdcdda28 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -148,7 +148,7 @@ class Translator { } } - return definitions; + return this.processKanji(definitions); } processTerm(groups, source, tags, rules=[], root='') { @@ -227,6 +227,39 @@ class Translator { } } + processKanji(entries) { + const results = []; + for (let entry of entries) { + const tagItems = []; + for (let tag of entry.tags) { + const tagItem = { + class: 'default', + order: Number.MAX_SAFE_INTEGER, + name: tag + }; + + const tagMeta = this.tagMeta[tag]; + if (tagMeta) { + for (const tagProp in tagMeta) { + tagItem[tagProp] = tagMeta[tagProp] || tagItem[tagProp]; + } + } + + tagItems.push(tagItem); + } + + results.push({ + character: entry.character, + kunyomi: entry.kunyomi, + onyomi: entry.onyomi, + tags: tagItems, + glossary: entry.glossary + }); + } + + return results; + } + static isKanji(c) { const code = c.charCodeAt(0); return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; -- cgit v1.2.3