Skip to content

Commit

Permalink
Displays source of data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Roberts committed Aug 26, 2016
1 parent 7d72434 commit 0078530
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
10 changes: 3 additions & 7 deletions api/bing-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ exports.Wrapper = function (Request, Promise, parseString, clientID, clientSecre
* PROMISE that, on success, returns an object with the following properties:
* translation (string) Text of the translation in `to` language
* source (string) Source of translation (bing)
* authors (object array) array of single object having properties
* url (string) https://www.microsoft.com/en-us/translator/translatorapi.aspx
*
* Now, you're probably wondering, why would we have an authors array with only one element?
* The answer is, unsatisfyingly, to stay consistent with Glosbe.
* url (string) https://www.microsoft.com/en-us/translator/translatorapi.aspx
*/
this.translate = function (x) {
if (!x) {
Expand Down Expand Up @@ -64,8 +60,8 @@ exports.Wrapper = function (Request, Promise, parseString, clientID, clientSecre
} else {
resolve({
translation: result.string._,
source: "bing",
authors: [ { url: "https://www.microsoft.com/en-us/translator/translatorapi.aspx" } ]
source: "Bing",
url: "https://www.microsoft.com/en-us/translator/translatorapi.aspx"
});
}
});
Expand Down
4 changes: 3 additions & 1 deletion api/glosbe-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function glosbeTranslateJsonToArray(data) {
});
return {
translation: tucElement.phrase.text,
source: "glosbe",
source: "Glosbe",
authors: authors
}
});
Expand All @@ -163,6 +163,7 @@ function glosbeTranslateJsonToArray(data) {
* Array whose elements have properties:
* toSentence (string) Sentence containing `phrase` in `to` language
* fromSentence (string) Sentence containing `phrase` in `from` language
* source (string) Name of website source (Glosbe)
* author (object) object having properties
* url (string) URL of source on glosbe
* id (int) unique author id on glosbe
Expand All @@ -173,6 +174,7 @@ function glosbeTMJsonToArray(data) {
return {
fromSentence: example.first,
toSentence: example.second,
source: "Glosbe",
author: {
id: example.author,
url: "https://www.glosbe.com/source/" + example.author
Expand Down
16 changes: 13 additions & 3 deletions data/wobtranslate-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
font-size: 20pt;
}

.source {
font-style: italic;
color: #666;
cursor: pointer;
}

.title {
font-weight: bold;
}
Expand Down Expand Up @@ -87,12 +93,16 @@
<button id="save-defaults">Save Defaults</button>
</div>
<div id="right" class="column">
<span id="translationtitle" class="title">Translation</span><br/>
<span id="translationtitle" class="title">Translation</span>
<span class="source" id="translationsource"></span>
<br/>
<span class="arrow" id="prevtranslation">&#9664;</span>
<textarea cols="30" rows="1" id="translation"></textarea>
<span class="arrow" id="nexttranslation">&#9654;</span>
<br /><br />
<span id="sentencetitle" class="title">Sentence</span><br/>
<br />
<span id="sentencetitle" class="title">Sentence</span>
<span class="source" id="sentencesource"></span>
<br/>
<span class="arrow" id="prevsentence">&#9664;</span>
<textarea cols="30" rows="1" id="sentence"></textarea>
<span class="arrow" id="nextsentence">&#9654;</span>
Expand Down
30 changes: 25 additions & 5 deletions data/wobtranslate-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var $sentenceTranslation = $('#sentenceTranslation');
var $error = $('#error');
var $translationTitle = $('#translationtitle');
var $sentenceTitle = $('#sentencetitle');
var $translationSource = $('#translationsource');
var $sentenceSource = $('#sentencesource');

var translations = [];
var sentences = [];
Expand Down Expand Up @@ -94,13 +96,13 @@ $('#save-translation').on('click', function () {
var trans = { phrase: $phrase.val() };
if (translation || $translation.data('changed')) {
trans.translation = $translation.val();
trans.translationAuthor = translation ? translation.authors : "";
trans.translationAuthor = translation ? translation.authors : translation.source;
}

if (sentence || $sentence.data('changed')) {
trans.fromSentence = $sentence.val();
trans.toSentence = $sentenceTranslation.val();
trans.sentenceAuthor = sentence ? sentence.author : "";
trans.sentenceAuthor = sentence ? sentence.author : sentence.source;
}

self.port.emit('addstore', 'translations', trans);
Expand Down Expand Up @@ -160,9 +162,17 @@ function request() {
function showTranslation() {
if (translationIndex >= translations.length) {
$translation.val("No translation found.");
$translationSource.off('click');
$translation.data('changed', false);
} else {
$translation.val(translations[translationIndex].translation);
var t = translations[translationIndex];
$translation.val(t.translation);
$translationSource.text("Source: " + t.source);
$translationSource.on('click', function () {
if (t.url) {
window.open(t.url);
}
});
}
}

Expand All @@ -174,9 +184,19 @@ function showSentence() {
//Set fields that are useful in determining what to save
$sentence.data('changed', false);
$sentenceTranslation.data('changed', false);
$sentenceSource.off('click');
} else {
$sentence.val(sentences[sentenceIndex].fromSentence);
$sentenceTranslation.val(sentences[sentenceIndex].toSentence);
var s = sentences[sentenceIndex];
$sentence.val(s.fromSentence);
$sentenceTranslation.val(s.toSentence);
$sentenceSource.text("Source: " + s.source);
$sentenceSource.on('click', function () {
if (s.url) {
window.open(s.url);
} else if (s.authors) {
window.open(s.authors[0].url);
}
});
}
}

Expand Down

0 comments on commit 0078530

Please sign in to comment.