Skip to content

Commit 18a16f4

Browse files
committed
v1.6.14: Glosbe API now uses javascript(browser based) instead of php(server based) to prevent possible retrieval errors
1 parent f9fa57a commit 18a16f4

7 files changed

Lines changed: 155 additions & 226 deletions

File tree

‎README.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Bulk translate new words in the reading frame
1717
Google api (use 'ggl.php' instead of '*http://translate.google.com' for Google Translate)
1818
Text to speech support (only words)
1919
Optional "ignore all" button in read texts
20-
New key bindings in the reading frame: T (translate sentence), P (pronounce term), G (edit term with Google Translate)
20+
Possibility to add images to terms
21+
New key bindings in the reading frame: T (translate sentence), P (pronounce term), G (edit term with Google Translate), J (edit term with Google Image Search)
2122
Ability to change audio playback speed (doesn't work when using the flash plugin)
2223
Improved Search/Query for Words/Texts
2324
Selecting terms according to a text tag

‎ggl.php‎

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -95,79 +95,48 @@ public static function staticTranslate($string, $from, $to) {
9595
header('Pragma: no-cache');
9696
header('Expires: 0');
9797

98-
$file = GoogleTranslate::staticTranslate($text,$sl,$tl);
98+
if(trim($text)!=''){
99+
$file = GoogleTranslate::staticTranslate($text,$sl,$tl);
99100

100-
$gglink = makeOpenDictStr(createTheDictLink('*http://translate.google.com/#' . $sl . '/' . $tl . '/',$text), " more...");
101+
$gglink = makeOpenDictStr(createTheDictLink('*http://translate.google.com/#' . $sl . '/' . $tl . '/',$text), " more...");
101102

102-
pagestart_nobody('');
103-
if (!isset($_GET['sent'])){
104-
echo '<h3>Google Translate: &nbsp; <span class="red2" id="textToSpeak" style="cursor:pointer" title="Click on expression for pronounciation" onclick="var txt = $(\'#textToSpeak\').text();var audio = new Audio();audio.src =\'tts.php?tl=' . $sl . '&q=\' + txt;audio.play();">' . tohtml($text) . '</span> <img id="del_translation" src="icn/broom.png" style="cursor:pointer" title="Empty Translation Field" onclick="deleteTranslation ();"></img></h3>';
105-
echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br />&nbsp;</p>';
106-
?>
107-
<script type="text/javascript">
108-
//<![CDATA[
109-
$(document).ready( function() {
110-
var w = window.parent.frames['ro'];
111-
if (typeof w == 'undefined') w = window.opener;
112-
if (typeof w == 'undefined')$('#del_translation').remove();
113-
});
114-
115-
function deleteTranslation (){
116-
var w = window.parent.frames['ro'];
117-
if (typeof w == 'undefined') w = window.opener;
118-
$('[name="WoTranslation"]',w.document).val('');
119-
w.makeDirty();
120-
}
103+
pagestart_nobody('');
104+
if (!isset($_GET['sent'])){
105+
echo '<h3>Google Translate: &nbsp; <span class="red2" id="textToSpeak" style="cursor:pointer" title="Click on expression for pronunciation" onclick="var txt = $(\'#textToSpeak\').text();var audio = new Audio();audio.src =\'tts.php?tl=' . $sl . '&q=\' + txt;audio.play();">' . tohtml($text) . '</span> <img id="del_translation" src="icn/broom.png" style="cursor:pointer" title="Empty Translation Field" onclick="deleteTranslation ();"></img></h3>';
106+
echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br />&nbsp;</p>';
107+
?>
108+
<script type="text/javascript" src="js/translation_api.js" charset="utf-8"></script>
109+
<script type="text/javascript">
110+
//<![CDATA[
111+
$(document).ready( function() {
112+
var w = window.parent.frames['ro'];
113+
if (typeof w == 'undefined') w = window.opener;
114+
if (typeof w == 'undefined')$('#del_translation').remove();
115+
});
121116

122-
function addTranslation (s) {
123-
var w = window.parent.frames['ro'];
124-
if (typeof w == 'undefined') w = window.opener;
125-
if (typeof w == 'undefined') {
126-
alert ('Translation can not be copied!');
127-
return;
128-
}
129-
var c = w.document.forms[0].WoTranslation;
130-
if (typeof c != 'object') {
131-
alert ('Translation can not be copied!');
132-
return;
133-
}
134-
var oldValue = c.value;
135-
if (oldValue.trim() == '') {
136-
c.value = s;
137-
w.makeDirty();
138-
}
139-
else {
140-
if (oldValue.indexOf(s) == -1) {
141-
c.value = oldValue + ' / ' + s;
142-
w.makeDirty();
117+
//]]>
118+
</script>
119+
<?php
120+
foreach($file as $word){
121+
echo '<span class="click" onclick="addTranslation(' . prepare_textdata_js($word) . ');"><img src="icn/tick-button.png" title="Copy" alt="Copy" /> &nbsp; ' . $word . '</span><br />';
143122
}
144-
else {
145-
if (confirm('"' + s + '" seems already to exist as a translation.\nInsert anyway?')) {
146-
c.value = oldValue + ' / ' + s;
147-
w.makeDirty();
148-
}
123+
if (!empty($file)) {
124+
echo '<br />' . $gglink . "\n";
149125
}
126+
127+
echo '&nbsp;<hr />&nbsp;<form action="ggl.php" method="get">Unhappy?<br/>Change term:
128+
<input type="text" name="text" maxlength="250" size="15" value="' . tohtml($text) . '">
129+
<input type="hidden" name="sl" value="' . tohtml($sl) . '">
130+
<input type="hidden" name="tl" value="' . tohtml($tl) . '">
131+
<input type="submit" value="Translate via Google Translate">
132+
</form>';
150133
}
134+
else echo '<h3>Sentence:</h3><span class="red2">' . tohtml($text) . '</span><br><br><h3>Google Translate:</h3>' . $gglink . '<br><table class="tab2" cellspacing="0" cellpadding="0"><tr><td class="td1bot center" colspan="1">'. $file[0] . '</td></tr></table>';
151135
}
152-
//]]>
153-
</script>
154-
<?php
155-
foreach($file as $word){
156-
echo '<span class="click" onclick="addTranslation(' . prepare_textdata_js($word) . ');"><img src="icn/tick-button.png" title="Copy" alt="Copy" /> &nbsp; ' . $word . '</span><br />';
157-
}
158-
if (!empty($file)) {
159-
echo '<br />' . $gglink . "\n";
160-
}
161-
162-
echo '&nbsp;<hr />&nbsp;<form action="ggl.php" method="get">Unhappy?<br/>Change term:
163-
<input type="text" name="text" maxlength="250" size="15" value="' . tohtml($text) . '">
164-
<input type="hidden" name="sl" value="' . tohtml($sl) . '">
165-
<input type="hidden" name="tl" value="' . tohtml($tl) . '">
166-
<input type="submit" value="Translate via Google Translate">
167-
</form>';
136+
else {
137+
pagestart_nobody('');
138+
echo "<p class=\"msgblue\">Term is not set!</p>";
168139
}
169-
else echo '<h3>Sentence:</h3><span class="red2">' . tohtml($text) . '</span><br><br><h3>Google Translate:</h3>' . $gglink . '<br><table class="tab2" cellspacing="0" cellpadding="0"><tr><td class="td1bot center" colspan="1">'. $file[0] . '</td></tr></table>';
170-
171140
pageend();
172141

173142
?>

‎glosbe_api.php‎

Lines changed: 14 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -58,169 +58,31 @@
5858
echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br />&nbsp;</p>';
5959

6060
?>
61+
<script type="text/javascript" src="js/translation_api.js" charset="utf-8"></script>
6162
<script type="text/javascript">
6263
//<![CDATA[
6364
$(document).ready( function() {
65+
<?php
66+
if($from=='' or $dest==''){
67+
echo '$("body").html("<p class=\"red\">There seems to be something wrong with the Glosbe API!</p><p class=\"red\">Please check the dictionaries in the Language Settings!</p>"); ';
68+
}
69+
else if($phrase==''){
70+
echo '$("body").html("<p class=\"msgblue\">Term is not set!</p>");';
71+
}
72+
else{
73+
?>
6474
var w = window.parent.frames['ro'];
6575
if (typeof w == 'undefined') w = window.opener;
6676
if (typeof w == 'undefined')$('#del_translation').remove();
77+
getGlosbeTranslation(<?php echo "'" ,urlencode($phrase) ,"','",$from,"','",$dest,"'"; ?>);
78+
<?php } ?>
6779
});
68-
69-
function deleteTranslation (){
70-
var w = window.parent.frames['ro'];
71-
if (typeof w == 'undefined') w = window.opener;
72-
$('[name="WoTranslation"]',w.document).val('');
73-
w.makeDirty();
74-
}
75-
76-
function addTranslation (s) {
77-
var w = window.parent.frames['ro'];
78-
if (typeof w == 'undefined') w = window.opener;
79-
if (typeof w == 'undefined') {
80-
alert ('Translation can not be copied!');
81-
return;
82-
}
83-
var c = w.document.forms[0].WoTranslation;
84-
if (typeof c != 'object') {
85-
alert ('Translation can not be copied!');
86-
return;
87-
}
88-
var oldValue = c.value;
89-
if (oldValue.trim() == '') {
90-
c.value = s;
91-
w.makeDirty();
92-
}
93-
else {
94-
if (oldValue.indexOf(s) == -1) {
95-
c.value = oldValue + ' / ' + s;
96-
w.makeDirty();
97-
}
98-
else {
99-
if (confirm('"' + s + '" seems already to exist as a translation.\nInsert anyway?')) {
100-
c.value = oldValue + ' / ' + s;
101-
w.makeDirty();
102-
}
103-
}
104-
}
105-
}
10680
//]]>
10781
</script>
82+
<p id="translations"></p>
10883
<?php
10984

110-
if ($from != '' && $dest != '' && $phrase != '') {
111-
112-
$glosbe_data = file_get_contents('http://glosbe.com/gapi/translate?from=' . urlencode($from) . '&dest=' . urlencode($dest) . '&format=json&phrase=' . urlencode($phrase));
113-
114-
if(! ($glosbe_data === FALSE)) {
115-
116-
$data = json_decode ($glosbe_data, true);
117-
if ( isset($data['phrase']) ) {
118-
$ok = (($data['phrase'] == $phrase) && (isset($data['tuc'])));
119-
}
120-
121-
}
122-
123-
}
124-
125-
if ( $ok ) {
126-
127-
if (count($data['tuc']) > 0) {
128-
129-
$i = 0;
130-
131-
echo "<p>\n";
132-
foreach ($data['tuc'] as &$value) {
133-
$word = '';
134-
if (isset($value['phrase'])) {
135-
if (isset($value['phrase']['text']))
136-
$word = $value['phrase']['text'];
137-
} else if (isset($value['meanings'])) {
138-
if (isset($value['meanings'][0]['text']))
139-
$word = "(" . $value['meanings'][0]['text'] . ")";
140-
}
141-
if ($word != '') {
142-
$word = trim(strip_tags($word));
143-
echo '<span class="click" onclick="addTranslation(' . prepare_textdata_js($word) . ');"><img src="icn/tick-button.png" title="Copy" alt="Copy" /> &nbsp; ' . $word . '</span><br />' . "\n";
144-
$i++;
145-
}
146-
}
147-
echo "</p>";
148-
if ($i) {
149-
echo '<p>&nbsp;<br/>' . $i . ' translation' . ($i==1 ? '' : 's') . ' retrieved via <a href="http://glosbe.com/a-api" API</a>.</p>';
150-
}
151-
152-
} else {
153-
154-
echo '<p>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').</p>';
155-
156-
if ($dest != "en" && $from != "en") {
157-
158-
$ok = FALSE;
159-
160-
$dest = "en";
161-
$titletext = '<a href="http://glosbe.com/' . $from . '/' . $dest . '/' . $phrase . '">Glosbe Dictionary (' . tohtml($from) . "-" . tohtml($dest) . "): &nbsp; <span class=\"red2\">" . tohtml($phrase) . "</span></a>";
162-
echo '<hr /><p>&nbsp;</p><h3>' . $titletext . '</h3>';
163-
164-
$glosbe_data = file_get_contents('http://glosbe.com/gapi/translate?from=' . urlencode($from) . '&dest=' . urlencode($dest) . '&format=json&phrase=' . urlencode($phrase));
165-
166-
if(! ($glosbe_data === FALSE)) {
167-
168-
$data = json_decode ($glosbe_data, true);
169-
if ( isset($data['phrase']) ) {
170-
$ok = (($data['phrase'] == $phrase) && (isset($data['tuc'])));
171-
}
172-
173-
}
174-
175-
if ( $ok ) {
176-
177-
if (count($data['tuc']) > 0) {
178-
179-
$i = 0;
180-
181-
echo "<p>&nbsp;<br />\n";
182-
foreach ($data['tuc'] as &$value) {
183-
$word = '';
184-
if (isset($value['phrase'])) {
185-
if (isset($value['phrase']['text']))
186-
$word = $value['phrase']['text'];
187-
} else if (isset($value['meanings'])) {
188-
if (isset($value['meanings'][0]['text']))
189-
$word = "(" . $value['meanings'][0]['text'] . ")";
190-
}
191-
if ($word != '') {
192-
$word = trim(strip_tags($word));
193-
echo '<span class="click" onclick="addTranslation(' . prepare_textdata_js($word) . ');"><img src="icn/tick-button.png" title="Copy" alt="Copy" /> &nbsp; ' . $word . '</span><br />' . "\n";
194-
$i++;
195-
}
196-
}
197-
echo "</p>";
198-
if ($i) {
199-
echo '<p>&nbsp;<br/>' . $i . ' translation' . ($i==1 ? '' : 's') . ' retrieved via <a href="http://glosbe.com/a-api" API</a>.</p>';
200-
}
201-
202-
} else {
203-
204-
echo '<p>&nbsp;<br/>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').</p>';
205-
206-
}
207-
208-
} else {
209-
210-
echo '<p>&nbsp;<br/>Retrieval error (' . tohtml($from) . '-' . tohtml($dest) . '). Possible reason: There is a limit of Glosbe API calls that may be done from one IP address in a fixed period of time, to prevent from abuse.</p>';
211-
212-
}
213-
}
214-
215-
}
216-
217-
} else {
218-
219-
echo '<p>Retrieval error (' . tohtml($from) . '-' . tohtml($dest) . '). Possible reason: There is a limit of Glosbe API calls that may be done from one IP address in a fixed period of time, to prevent from abuse.</p>';
220-
221-
}
222-
223-
echo '&nbsp;<hr />&nbsp;<form action="glosbe_api.php" method="get">Unhappy?<br/>Change term:
85+
echo '&nbsp;<form action="glosbe_api.php" method="get">Unhappy?<br/>Change term:
22486
<input type="text" name="phrase" maxlength="250" size="15" value="' . tohtml($phrase) . '">
22587
<input type="hidden" name="from" value="' . tohtml($from) . '">
22688
<input type="hidden" name="dest" value="' . tohtml($destorig) . '">

‎info.htm‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ <h4>
249249

250250
<dd>
251251
<ul>
252-
<li>The current version is <b>1.6.13 (March 23 2015)</b>.
252+
<li>The current version is <b>1.6.14 (March 28 2015)</b>.
253253
</li>
254254

255255
<li>
@@ -558,10 +558,13 @@ <h4>
558558
</li>
559559
<li>Optional "ignore all" button in read texts
560560
</li>
561+
<li>Possibility to add images to terms
562+
</li>
561563
<li>New key bindings in the reading frame:
562564
<ul><li>T (translate sentence),</li>
563565
<li>P (pronounce term),</li>
564-
<li> G (edit term with Google Translate)
566+
<li>G (edit term with Google Translate),</li>
567+
<li>J (edit term with Google Image Search)
565568
</li></ul>
566569
</li>
567570
<li>Ability to change audio playback speed (doesn't work when using the flash plugin)
@@ -2293,7 +2296,7 @@ <h4>
22932296
<dd>
22942297
<ul>
22952298
<li>
2296-
The following sixteen tables are one "LWT table set". The default table set has no table name prefix, so the tables are named just as written below: "settings", "languages", etc.
2299+
The following seventeen tables are one "LWT table set". The default table set has no table name prefix, so the tables are named just as written below: "settings", "languages", etc.
22972300
<br />
22982301
<br />
22992302
Additional table sets have its "table set name" plus an underscore "_" as a table name prefix: "setname_settings", "setname_languages", etc.
@@ -2372,7 +2375,7 @@ <h4>
23722375
<br />
23732376
TxSourceURI varchar(1000) DEFAULT NULL,
23742377
<br />
2375-
TxPosition int(6) NOT NULL DEFAULT '0',
2378+
TxPosition smallint(5) NOT NULL DEFAULT '0',
23762379
<br />
23772380
TxAudioPosition float NOT NULL DEFAULT '0',
23782381
<br />
@@ -2691,7 +2694,20 @@ <h4>
26912694
KEY NfLgID (NfLgID),
26922695
<br />
26932696
KEY NfUpdate (NfUpdate)
2697+
<br />
2698+
<br />
26942699
</li>
2700+
<li>
2701+
<b>Table "images" (Term image relations, no backup possible):</b>
2702+
<br />
2703+
ImID smallint(5) NOT NULL AUTO_INCREMENT,
2704+
<br />
2705+
ImWoID mediumint(8) NOT NULL,
2706+
<br />
2707+
PRIMARY KEY (ImID),
2708+
<br />
2709+
UNIQUE KEY ImWoID (ImWoID)
2710+
</li>
26952711
</ul>
26962712
</dd>
26972713

@@ -2701,6 +2717,12 @@ <h4>
27012717

27022718
<dd>
27032719
<ul>
2720+
<li>1.6.14 (March 28 2015):<br />
2721+
Glosbe API now uses javascript(browser based) instead of php(server based) to prevent possible retrieval errors when LWT is installed on a webhoster for multiple users.<br />
2722+
<br />
2723+
</li>
2724+
2725+
27042726
<li>1.6.13 (March 23 2015):<br />
27052727
Bugfix: 'error when making backup' fixed<br />
27062728
New Setting: Tooltips (JQueryUI will show images in Tooltips in the Read Text Screen)<br />

0 commit comments

Comments
 (0)