forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
glosbe_api.php
60 lines (52 loc) · 2.28 KB
/
glosbe_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Call Glosbe Translation API, analyze and present JSON results
* for easily filling the "new word form"
*
* Call: glosbe_api.php?from=...&dest=...&phrase=...
* ... from=L2 language code (see Glosbe)
* ... dest=L1 language code (see Glosbe)
* ... phrase=... word or expression to be translated by
* Glosbe API (see http://glosbe.com/a-api)
*
* PHP version 8.1
*/
require_once 'inc/session_utility.php';
$from = trim($_REQUEST["from"]);
$dest = trim($_REQUEST["dest"]);
$destorig = $dest;
$phrase = mb_strtolower(trim($_REQUEST["phrase"]), 'UTF-8');
pagestart_nobody('');
$titletext = '<a href="http://glosbe.com/' . $from . '/' . $dest . '/' . $phrase . '">Glosbe Dictionary (' . tohtml($from) . "-" . tohtml($dest) . "): <span class=\"red2\">" . tohtml($phrase) . "</span></a>";
echo '<h3>' . $titletext . ' <img id="del_translation" src="icn/broom.png" title="Empty Translation Field" style="cursor:pointer" onclick="deleteTranslation ();"></img></h3>';
echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br /> </p>';
?>
<script type="text/javascript">
//<![CDATA[
$(document).ready( function() {
<?php
if($from=='' or $dest=='') {
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>"); ';
} else if($phrase=='') {
echo '$("body").html("<p class=\"msgblue\">Term is not set!</p>");';
} else {
?>
var w = window.parent.frames['ro'];
if (typeof w == 'undefined') w = window.opener;
if (typeof w == 'undefined')$('#del_translation').remove();
getGlosbeTranslation(<?php echo "'" ,urlencode($phrase) ,"','",$from,"','",$dest,"'"; ?>);
<?php
} ?>
});
//]]>
</script>
<p id="translations"></p>
<?php
echo ' <form action="glosbe_api.php" method="get">Unhappy?<br/>Change term:
<input type="text" name="phrase" maxlength="250" size="15" value="' . tohtml($phrase) . '">
<input type="hidden" name="from" value="' . tohtml($from) . '">
<input type="hidden" name="dest" value="' . tohtml($destorig) . '">
<input type="submit" value="Translate via Glosbe">
</form>';
pageend();
?>