|
58 | 58 | echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br /> </p>'; |
59 | 59 |
|
60 | 60 | ?> |
| 61 | +<script type="text/javascript" src="js/translation_api.js" charset="utf-8"></script> |
61 | 62 | <script type="text/javascript"> |
62 | 63 | //<![CDATA[ |
63 | 64 | $(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 | +?> |
64 | 74 | var w = window.parent.frames['ro']; |
65 | 75 | if (typeof w == 'undefined') w = window.opener; |
66 | 76 | if (typeof w == 'undefined')$('#del_translation').remove(); |
| 77 | + getGlosbeTranslation(<?php echo "'" ,urlencode($phrase) ,"','",$from,"','",$dest,"'"; ?>); |
| 78 | +<?php } ?> |
67 | 79 | }); |
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 | | -} |
106 | 80 | //]]> |
107 | 81 | </script> |
| 82 | +<p id="translations"></p> |
108 | 83 | <?php |
109 | 84 |
|
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" /> ' . $word . '</span><br />' . "\n"; |
144 | | - $i++; |
145 | | - } |
146 | | - } |
147 | | - echo "</p>"; |
148 | | - if ($i) { |
149 | | - echo '<p> <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) . "): <span class=\"red2\">" . tohtml($phrase) . "</span></a>"; |
162 | | - echo '<hr /><p> </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> <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" /> ' . $word . '</span><br />' . "\n"; |
194 | | - $i++; |
195 | | - } |
196 | | - } |
197 | | - echo "</p>"; |
198 | | - if ($i) { |
199 | | - echo '<p> <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> <br/>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').</p>'; |
205 | | - |
206 | | - } |
207 | | - |
208 | | - } else { |
209 | | - |
210 | | - echo '<p> <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 ' <hr /> <form action="glosbe_api.php" method="get">Unhappy?<br/>Change term: |
| 85 | +echo ' <form action="glosbe_api.php" method="get">Unhappy?<br/>Change term: |
224 | 86 | <input type="text" name="phrase" maxlength="250" size="15" value="' . tohtml($phrase) . '"> |
225 | 87 | <input type="hidden" name="from" value="' . tohtml($from) . '"> |
226 | 88 | <input type="hidden" name="dest" value="' . tohtml($destorig) . '"> |
|
0 commit comments