Skip to content

Commit

Permalink
Added output language to translation and moved translation output aft…
Browse files Browse the repository at this point in the history
…er dropdowns
  • Loading branch information
desmovalvo committed Jul 13, 2018
1 parent 0cc8be5 commit 48a93b7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client/parts/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ <h5 ng-show="recordings">Recordings</h5>
<div class="menu" ng-hide="visible">
<input id="mainsearch" type="text" class="busca control" ng-model="query" placeholder="search"/>


<select ng-options="o.name for o in languages" ng-model="selectedLangIn"></select>
<select ng-options="o.name for o in languages" ng-model="selectedLangOut"></select>
<span id="translations" ng-click="searchTranslatedKeyword()"></span>
<select data-ng-options="o.name for o in languages" data-ng-model="selectedOption"></select>

<!-- translation: input language -->
<!--<button class="zoom-out fa fa-minus"></button>-->
Expand Down
41 changes: 33 additions & 8 deletions client/scripts/controllers/query.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
app.controller('queryController', ['$scope','$window', '$http', '$location', '$filter', '$sce', '$interval', function ($scope, $window, $http, $location, $filter, $sce, $interval ) {

$scope.languages = [ { name: "de", id: 1 }, { name: "bg", id: 2 }, { name: "hu", id: 3 }, { name: "nl", id: 4 }, { name: "el", id: 5 }, { name: "ka", id: 6 }, { name: "da", id: 7 }, { name: "it", id: 8 }, { name: "es", id: 9 }, { name: "ja", id: 10 }, { name: "fr", id: 11 }, { name: "fi", id: 12 }, { name: "ur", id: 13 }, { name: "tr", id: 14 }, { name: "pt", id: 15 }, { name: "ro", id: 16 }, { name: "ru", id: 17 } ];
$scope.selectedOption = $scope.languages[1];
$scope.selectedLangIn = $scope.languages[1];
$scope.selectedLangOut = $scope.languages[1];
var sounds = [];
$scope.sounds = sounds;

Expand All @@ -17,15 +18,30 @@ $scope.about= 'estreito';
//$scope.query = 'gfun';


$scope.$watch('selectedLangOut', function(){
q = $scope.query;
lin = $scope.selectedLangIn;
lout = $scope.selectedLangOut;
if (q !== undefined)
$scope.makeTranslationQuery("/translation/" + lin["name"] + "/" + lout["name"] + "/" + q, q);
})

$scope.$watch('selectedLangIn', function(){
q = $scope.query;
lin = $scope.selectedLangIn;
lout = $scope.selectedLangOut;
if (q !== undefined)
$scope.makeTranslationQuery("/translation/" + lin["name"] + "/" + lout["name"] + "/" + q, q);
})

$scope.$watch('query', function() {

// translation: get input language
console.log("Translating keyword!")
try {
console.log("***" + $scope.query + "***");

if (($scope.query !== "") && ($scope.query !== undefined))
$scope.makeTranslationQuery("/translation/" + $scope.selectedOption["name"] + "/" + $scope.query, $scope.query);
$scope.makeTranslationQuery("/translation/" + $scope.selectedLangIn["name"] + "/" + $scope.selectedLangOut["name"] + "/" + $scope.query, $scope.query);
} catch(err){
console.log("Translation not ready");
console.log(err)
Expand Down Expand Up @@ -83,8 +99,15 @@ $scope.singlequery = function(soundid) {

$scope.makeTranslationQuery = function(urlbase, query) {

console.log("[DVL] makeTranslationQuery");
console.log(urlbase)
console.log("[DVL] makeTranslationQuery");
console.log(urlbase)

try{
t = document.getElementById("translations");
t.innerHTML = "";
} catch(err){
console.log(err);
}

var req = {
method: 'GET',
Expand All @@ -98,7 +121,6 @@ $scope.singlequery = function(soundid) {

$.ajax(req).
then(function(response) {


// when the response is available
// try to parse the response as a JSON message
Expand All @@ -109,9 +131,12 @@ $scope.singlequery = function(soundid) {
t = document.getElementById("translations");
if ((t !== undefined) && (t !== null)){
for (word in jr["text"]){
if ((jr["text"][word] !== query) && (jr["text"][word] !== undefined)){
if (jr["text"][word] !== undefined) {
t.innerHTML = jr["text"][word];
}
}
else {
t.innerHTML = "";
}
}
}
else {
Expand Down
7 changes: 4 additions & 3 deletions routes/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const stringFromQuery = (queryObj) => {
router.all('*', (req, resp, next) => {

// prepare request path
lang = req.url.split("/")[1];
word = req.url.split("/")[2];
finalURI = yandexPath + "?key=" + yandexKey + "&text=" + word + "&lang=" + lang + "-en";
langIn = req.url.split("/")[1];
langOut = req.url.split("/")[2];
word = req.url.split("/")[3];
finalURI = yandexPath + "?key=" + yandexKey + "&text=" + word + "&lang=" + langIn + "-" + langOut;

// setting request options
const options = {
Expand Down

0 comments on commit 48a93b7

Please sign in to comment.