Skip to content

Commit

Permalink
update string names
Browse files Browse the repository at this point in the history
  • Loading branch information
thedannywahl committed Feb 15, 2019
1 parent 98b5535 commit 2cd93e8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
46 changes: 36 additions & 10 deletions src/langs/sentimony.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
import emotions from '../modules/emotions'

var Langs = function(options) {
this.options = options;
};

Langs.prototype.strings = {
en: {
title: function() {return "Sentimony"},
ok: function () {return "OK"},
selectCategory: function() {return "Select a category"},
overview: function() {return "Sentiment Overview"},
score: function() {return "Sentiment Details"},
report: function(data) {
buttonOk: function () {return "OK"},
sentimentPositive: "positive",
sentimentPegative: "negative",
labelSelectCategory: function() {return "Select a category"},
labelOverview: function() {return "Sentiment Overview"},
labelScore: function() {return "Sentiment Details"},
containerReport: function(data) {
let sentiment = "neutral"
if (data.score > 0) sentiment = "positive"
if (data.score < 0) sentiment = "negative"
return `<p>Overall, readers might see your sentiment as ${sentiment}
because you used words like <span class="keyword">${data.negative[0]}</span>
${data.negative[1] ? `and <span class="keyword">${data.negative[1]}</span>` : ''}</p>`
let emotion = "neutral"
if (data.comparative > 0) {
sentiment = "positive"
emotion = "joy"
}
if (data.comparative < 0) {
sentiment = "negative"
emotion = "sadness"
}
let strength = Langs.prototype.comparativeToScale(data, emotion)

if (data.comparative == 0) {
return `<p>Overall, readers might have a hard time understanding your
sentiment because none of your words seem to have a feeling or
emotion associated wiith them`
}
return `<p><span>${strength.html}</span></p>
<p>Overall, readers might see your sentiment as
<span class="keyword">${strength.scale}</span> ${sentiment}
because you used words like <span class="keyword">${data[sentiment][0]}</span>
${data[sentiment][1] ? `and <span class="keyword">${data[sentiment][1]}</span>` : ''}
</p>`
}
}
}


Langs.prototype.t = function(l = 'en', s, d) {
if(this.strings[l] === undefined) l = 'en'
return this.strings[l][s](d)
}

Langs.prototype.comparativeToScale = function(data, emotion) {
return emotions[emotion]["slightly"]
}

module.exports = Langs;
8 changes: 4 additions & 4 deletions src/modules/sentimony.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Sentimony = function(options) {
this.options = options;
};

Sentimony.prototype.setComparativeEmotion = function(data, emotions) {
Sentimony.prototype.setComparativeSentiment = function(data, emotions) {
let emotion = document.getElementById("sentimony-emotion")
if (data.comparative > 0) {
emotion.setAttribute("aria-label", emotions.joy.slightly.name)
Expand All @@ -29,14 +29,14 @@ Sentimony.prototype.setComparativeEmotion = function(data, emotions) {

Sentimony.prototype.showReport = function(section, data) {

let overview = s.t(l, "overview report")
let score = `${s.t(l, "score")}: ${data.score}`
let overview = s.t(l, "containerReport", data)
let score = `Score: ${data.score}`


let reportBody = document.getElementById("sentimony-report-body")
let report = overview
if (reportBody) {
if (section == s.t(l, "score")) report = score
if (section == s.t(l, "labelScore")) report = score
reportBody.innerHTML = report
} else {
return report
Expand Down
12 changes: 6 additions & 6 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ const plugin = editor => {
onclick: function() {
editor.windowManager.open({
title: s.t(l, "title"),
buttons: [{text: s.t(l, "ok"), onClick: 'close'}],
buttons: [{text: s.t(l, "buttonOk"), onClick: 'close'}],
width: 425,
height: 250,
layout: 'flex',
body: [
{
type : 'listbox',
name : 'categories',
label : s.t(l, "selectCategory"),
label : s.t(l, "labelSelectCategory"),
onselect: function(e) {
let selectedSection = this.$el[0].innerText
sentimony.showReport(selectedSection, globalData)
},
values : [
{text: s.t(l, "overview"), value: s.t(l, "overview"), selected: true},
{text: s.t(l, "score"), value: s.t(l, "score")}
{text: s.t(l, "labelOverview"), value: s.t(l, "labelOverview"), selected: true},
{text: s.t(l, "labelScore"), value: s.t(l, "labelScore")}
]
},
{
Expand All @@ -47,7 +47,7 @@ const plugin = editor => {
{
type: 'container',
id: 'sentimony-report',
html: sentimony.showReport(s.t(l, "overview"), globalData),
html: sentimony.showReport(s.t(l, "labelOverview"), globalData),
}
]
},)
Expand All @@ -58,7 +58,7 @@ const plugin = editor => {
editor.on('Change', function(e) {
sentiment.analyze(editor.getContent({format:'text'}), {}, function(i,data) {
globalData = data
sentimony.setComparativeEmotion(globalData, emotions)
sentimony.setComparativeSentiment(globalData, emotions)
console.log(globalData)
})
})
Expand Down

0 comments on commit 2cd93e8

Please sign in to comment.