849bdf42 |
1 | <?php |
2 | |
3 | /* Easy plugin that sends the body of the message to a new browser |
4 | window using the specified translator. It can also translate your |
5 | outgoing message if you send it to someone in a different country. |
6 | |
7 | Languages from i18n, incorporated in the auto-language selection: |
8 | en - English |
9 | no - Norwegian (Bokmål) |
10 | no_NO_ny - Norwegian (Nynorsk) |
11 | de - Deutsch |
12 | ru - Russian KOI8-R |
13 | pl - Polish |
14 | sv - Swedish |
15 | nl - Dutch |
16 | pt_BR - Portuguese (Brazil) |
17 | fr - French |
18 | it - Italian |
19 | cs - Czech |
20 | es - Spanish |
21 | ko - Korean |
22 | */ |
23 | |
24 | |
25 | /* Initialize the translation plugin */ |
26 | function squirrelmail_plugin_init_translate() { |
27 | global $squirrelmail_plugin_hooks; |
28 | |
29 | $squirrelmail_plugin_hooks['read_body_bottom']['translate'] = 'translate_read_form'; |
30 | $squirrelmail_plugin_hooks['options_register']['translate'] = 'translate_opt'; |
31 | $squirrelmail_plugin_hooks['options_save']['translate'] = 'translate_sav'; |
32 | $squirrelmail_plugin_hooks['loading_prefs']['translate'] = 'translate_pref'; |
33 | $squirrelmail_plugin_hooks['compose_button_row']['translate'] = 'translate_button'; |
34 | } |
35 | |
36 | |
37 | /* Show the translation for a message you're reading */ |
38 | function translate_read_form() { |
39 | global $color, $translate_server; |
40 | global $body, $translate_dir; |
41 | global $translate_show_read; |
42 | |
43 | if (!$translate_show_read) { |
44 | return; |
45 | } |
46 | |
47 | $translate_dir = 'to'; |
48 | |
49 | $new_body = $body; |
50 | $pos = strpos($new_body, |
51 | '">Download this as a file</A></CENTER><BR></SMALL>'); |
52 | if (is_int($pos)) { |
53 | $new_body = substr($new_body, 0, $pos); |
54 | } |
55 | |
56 | $trans = get_html_translation_table('HTMLENTITIES'); |
57 | $trans[' '] = ' '; |
58 | $trans = array_flip($trans); |
59 | $new_body = strtr($new_body, $trans); |
60 | |
61 | $new_body = urldecode($new_body); |
62 | $new_body = strip_tags($new_body); |
63 | |
64 | /* I really don't like this next part ... */ |
65 | $new_body = str_replace('"', "''", $new_body); |
66 | $new_body = strtr($new_body, "\n", ' '); |
67 | |
68 | $function = 'translate_form_' . $translate_server; |
69 | $function($new_body); |
70 | } |
71 | |
72 | function translate_table_end() { |
73 | ?></td> |
74 | </tr> |
75 | </table> |
76 | </td> |
77 | </tr> |
78 | </table> |
79 | </form> |
80 | <?php |
81 | } |
82 | |
83 | |
84 | function translate_button() { |
85 | global $translate_show_send; |
86 | |
87 | if (! $translate_show_send) { |
88 | return; |
89 | } |
90 | } |
91 | |
92 | |
93 | function translate_opt() { |
94 | global $optionpages; |
95 | $optionpages[] = array( |
96 | 'name' => 'Translation Options', |
97 | 'url' => '../plugins/translate/options.php', |
98 | 'desc' => 'Which translator should be used when you get messages in a different language?', |
99 | 'js' => false |
100 | ); |
101 | } |
102 | |
103 | function translate_sav() { |
104 | global $username,$data_dir; |
105 | global $submit_translate, $translate_translate_server; |
106 | global $translate_translate_location; |
107 | global $translate_translate_show_read; |
108 | global $translate_translate_show_send; |
109 | global $translate_translate_same_window; |
110 | |
111 | if ($submit_translate) { |
112 | if (isset($translate_translate_server)) { |
113 | setPref($data_dir, $username, 'translate_server', $translate_translate_server); |
114 | } else { |
115 | setPref($data_dir, $username, 'translate_server', 'babelfish'); |
116 | } |
117 | |
118 | if (isset($translate_translate_location)) { |
119 | setPref($data_dir, $username, 'translate_location', $translate_translate_location); |
120 | } else { |
121 | setPref($data_dir, $username, 'translate_location', 'center'); |
122 | } |
123 | |
124 | if (isset($translate_translate_show_read)) { |
125 | setPref($data_dir, $username, 'translate_show_read', '1'); |
126 | } else { |
127 | setPref($data_dir, $username, 'translate_show_read', ''); |
128 | } |
129 | |
130 | if (isset($translate_translate_show_send)) { |
131 | setPref($data_dir, $username, 'translate_show_send', '1'); |
132 | } else { |
133 | setPref($data_dir, $username, 'translate_show_send', ''); |
134 | } |
135 | |
136 | if (isset($translate_translate_same_window)) { |
137 | setPref($data_dir, $username, 'translate_same_window', '1'); |
138 | } else { |
139 | setPref($data_dir, $username, 'translate_same_window', ''); |
140 | } |
141 | |
142 | echo '<center>Translation options saved.</center>'; |
143 | } |
144 | } |
145 | |
146 | |
147 | function translate_pref() { |
148 | global $username, $data_dir; |
149 | global $translate_server, $translate_location; |
150 | global $translate_show_send, $translate_show_read; |
151 | global $translate_same_window; |
152 | |
153 | $translate_server = getPref($data_dir, $username, 'translate_server'); |
154 | if ($translate_server == '') { |
155 | $translate_server = 'babelfish'; |
156 | } |
157 | |
158 | $translate_location = getPref($data_dir, $username, 'translate_location'); |
159 | if ($translate_location == '') { |
160 | $translate_location = 'center'; |
161 | } |
162 | |
163 | $translate_show_send = getPref($data_dir, $username, 'translate_show_send'); |
164 | $translate_show_read = getPref($data_dir, $username, 'translate_show_read'); |
165 | $translate_same_window = getPref($data_dir, $username, 'translate_same_window'); |
166 | } |
167 | |
168 | |
169 | /** |
170 | * This function could be sped up. |
171 | * It basically negates the process if a ! is found in the beginning and |
172 | * matches a * at the end with 0 or more characters. |
173 | */ |
174 | function translate_does_it_match_language($test) { |
175 | global $squirrelmail_language; |
176 | $true = 1; |
177 | $false = 0; |
178 | $index = 0; |
179 | $smindex = 0; |
180 | |
181 | if (! $test || ! $squirrelmail_language) { |
182 | return $false; |
183 | } |
184 | |
185 | if ($test[$index] == '!') { |
186 | $index ++; |
187 | $true = 0; |
188 | $false = 1; |
189 | } |
190 | |
191 | if (($index == 0) && ($test == $squirrelmail_language)) { |
192 | return $true; |
193 | } |
194 | |
195 | while ($test[$index]) { |
196 | if ($test[$index] == '*') { |
197 | return $true; |
198 | } |
199 | if ($test[$index] != $squirrelmail_language[$smindex]) { |
200 | return $false; |
201 | } |
202 | $index ++; |
203 | $smindex ++; |
204 | } |
205 | |
206 | return $false; |
207 | } |
208 | |
209 | |
210 | function translate_lang_opt($from, $to, $value, $text) { |
211 | global $translate_dir; |
212 | |
213 | echo ' <option value="' . $value . '"'; |
214 | |
215 | if (translate_does_it_match_language($to) && ($translate_dir == 'to')) { |
216 | echo ' SELECTED'; |
217 | } |
218 | |
219 | if (translate_does_it_match_language($from) && ($translate_dir == 'from')) { |
220 | echo ' SELECTED'; |
221 | } |
222 | |
223 | echo '>' . $text . "</option>\n"; |
224 | } |
225 | |
226 | |
227 | function translate_new_form($action) { |
228 | global $translate_dir, $translate_new_window, $translate_location; |
229 | global $color, $translate_same_window; |
230 | |
231 | echo '<form action="'; |
232 | |
233 | if ($translate_dir == 'to') { |
234 | echo $action; |
235 | } else { |
236 | echo 'translate.php'; |
237 | } |
238 | |
239 | echo '" method="post"'; |
240 | |
241 | if (!$translate_same_window) { |
242 | echo ' target="_blank"'; |
243 | } |
244 | |
245 | echo ">\n"; |
246 | |
247 | ?><table align="<?php echo $translate_location ?>" cellpadding=3 cellspacing=0 border=0 bgcolor=<?php echo $color[10] ?>> |
248 | <tr> |
249 | <td> |
250 | <table cellpadding=2 cellspacing=1 border=0 bgcolor="<?php echo $color[5] ?>"> |
251 | <tr> |
252 | <td><?php |
253 | } |
254 | |
255 | function translate_form_babelfish($message) { |
256 | translate_new_form('http://babelfish.altavista.com/translate.dyn'); |
257 | ?> |
258 | <input type="hidden" name="doit" value="done"> |
259 | <input type="hidden" name="BabelFishFrontPage" value="yes"> |
260 | <input type="hidden" name="bblType" value="urltext"> |
261 | <input type="hidden" name="urltext" value="<?php echo $message; ?>"> |
262 | <select name="lp"><?php |
263 | translate_lang_opt('en', 'fr', 'en_fr', 'English to French'); |
264 | translate_lang_opt('', 'de', 'en_de', 'English to German'); |
265 | translate_lang_opt('', 'it', 'en_it', 'English to Italian'); |
266 | translate_lang_opt('', 'pt*', 'en_pt', 'English to Portuguese'); |
267 | translate_lang_opt('', 'es', 'en_es', 'English to Spanish'); |
268 | translate_lang_opt('fr', 'en', 'fr_en', 'French to English'); |
269 | translate_lang_opt('de', '', 'de_en', 'German to English'); |
270 | translate_lang_opt('it', '', 'it_en', 'Italian to English'); |
271 | translate_lang_opt('pt*', '', 'pt_en', 'Portuguese to English'); |
272 | translate_lang_opt('es', '', 'es_en', 'Spanish to English'); |
273 | translate_lang_opt('', '', 'de_fr', 'German to French'); |
274 | translate_lang_opt('', '', 'fr_de', 'French to German'); |
275 | translate_lang_opt('ru', '', 'ru_en', 'Russian to English'); |
276 | ?></select> |
277 | Babelfish: <input type="Submit" value="Translate"> |
278 | <?php |
279 | translate_table_end(); |
280 | } |
281 | |
282 | function translate_form_go($message) { |
283 | translate_new_form('http://translator.go.com/cb/trans_entry'); |
284 | ?> |
285 | <input type=hidden name=input_type value=text> |
286 | <select name=lp><?php |
287 | translate_lang_opt('en', 'es', 'en_sp', 'English to Spanish'); |
288 | translate_lang_opt('', 'fr', 'en_fr', 'English to French'); |
289 | translate_lang_opt('', 'de', 'en_ge', 'English to German'); |
290 | translate_lang_opt('', 'it', 'en_it', 'English to Italian'); |
291 | translate_lang_opt('', 'pt', 'en_pt', 'English to Portuguese'); |
292 | translate_lang_opt('es', 'en', 'sp_en', 'Spanish to English'); |
293 | translate_lang_opt('fr', '', 'fr_en', 'French to English'); |
294 | translate_lang_opt('de', '', 'ge_en', 'German to English'); |
295 | translate_lang_opt('it', '', 'it_en', 'Italian to English'); |
296 | translate_lang_opt('pt', '', 'pt_en', 'Portuguese to English'); |
297 | ?></select> |
298 | <input type="hidden" name="text" value="<?php echo $message ?>"> |
299 | Go.com: <input type="Submit" value="Translate"> |
300 | <?php |
301 | translate_table_end(); |
302 | } |
303 | |
304 | function translate_form_intertran($message) { |
305 | translate_new_form('http://www.tranexp.com:2000/InterTran'); |
306 | ?> |
307 | <INPUT TYPE="hidden" NAME="topframe" VALUE="yes"> |
308 | <INPUT TYPE="hidden" NAME="type" VALUE="text"> |
309 | <input type="hidden" name="text" value="<?php echo $message ?>"> |
310 | <SELECT name="from"><?PHP |
311 | translate_lang_opt('pt_BR', '', 'pob', 'Brazilian Portuguese'); |
312 | translate_lang_opt('', '', 'bul', 'Bulgarian (CP 1251)'); |
313 | translate_lang_opt('', '', 'cro', 'Croatian (CP 1250)'); |
314 | translate_lang_opt('cs', '', 'che', 'Czech (CP 1250)'); |
315 | translate_lang_opt('', '', 'dan', 'Danish'); |
316 | translate_lang_opt('nl', '', 'dut', 'Dutch'); |
317 | translate_lang_opt('en', '!en', 'eng', 'English'); |
318 | translate_lang_opt('', '', 'spe', 'European Spanish'); |
319 | translate_lang_opt('', '', 'fin', 'Finnish'); |
320 | translate_lang_opt('fr', '', 'fre', 'French'); |
321 | translate_lang_opt('de', '', 'ger', 'German'); |
322 | translate_lang_opt('', '', 'grk', 'Greek'); |
323 | translate_lang_opt('', '', 'hun', 'Hungarian (CP 1250)'); |
324 | translate_lang_opt('', '', 'ice', 'Icelandic'); |
325 | translate_lang_opt('it', '', 'ita', 'Italian'); |
326 | translate_lang_opt('', '', 'jpn', 'Japanese (Shift JIS)'); |
327 | translate_lang_opt('', '', 'spl', 'Latin American Spanish'); |
328 | translate_lang_opt('no*', '', 'nor', 'Norwegian'); |
329 | translate_lang_opt('pl', '', 'pol', 'Polish (ISO 8859-2)'); |
330 | translate_lang_opt('', '', 'poe', 'Portuguese'); |
331 | translate_lang_opt('', '', 'rom', 'Romanian (CP 1250)'); |
332 | translate_lang_opt('ru', '', 'rus', 'Russian (CP 1251)'); |
333 | translate_lang_opt('', '', 'sel', 'Serbian (CP 1250)'); |
334 | translate_lang_opt('', '', 'slo', 'Slovenian (CP 1250)'); |
335 | translate_lang_opt('es', '', 'spa', 'Spanish'); |
336 | translate_lang_opt('sv', '', 'swe', 'Swedish'); |
337 | translate_lang_opt('', '', 'wel', 'Welsh'); |
338 | ?></SELECT> to <SELECT name="to"><?PHP |
339 | translate_lang_opt('', 'pt_BR', 'pob', 'Brazilian Portuguese'); |
340 | translate_lang_opt('', '', 'bul', 'Bulgarian (CP 1251)'); |
341 | translate_lang_opt('', '', 'cro', 'Croatian (CP 1250)'); |
342 | translate_lang_opt('', 'cs', 'che', 'Czech (CP 1250)'); |
343 | translate_lang_opt('', '', 'dan', 'Danish'); |
344 | translate_lang_opt('', 'nl', 'dut', 'Dutch'); |
345 | translate_lang_opt('!en', 'en', 'eng', 'English'); |
346 | translate_lang_opt('', '', 'spe', 'European Spanish'); |
347 | translate_lang_opt('', '', 'fin', 'Finnish'); |
348 | translate_lang_opt('', 'fr', 'fre', 'French'); |
349 | translate_lang_opt('', 'de', 'ger', 'German'); |
350 | translate_lang_opt('', '', 'grk', 'Greek'); |
351 | translate_lang_opt('', '', 'hun', 'Hungarian (CP 1250)'); |
352 | translate_lang_opt('', '', 'ice', 'Icelandic'); |
353 | translate_lang_opt('', 'it', 'ita', 'Italian'); |
354 | translate_lang_opt('', '', 'jpn', 'Japanese (Shift JIS)'); |
355 | translate_lang_opt('', '', 'spl', 'Latin American Spanish'); |
356 | translate_lang_opt('', 'no*', 'nor', 'Norwegian'); |
357 | translate_lang_opt('', 'pl', 'pol', 'Polish (ISO 8859-2)'); |
358 | translate_lang_opt('', '', 'poe', 'Portuguese'); |
359 | translate_lang_opt('', '', 'rom', 'Romanian (CP 1250)'); |
360 | translate_lang_opt('', 'ru', 'rus', 'Russian (CP 1251)'); |
361 | translate_lang_opt('', '', 'sel', 'Serbian (CP 1250)'); |
362 | translate_lang_opt('', '', 'slo', 'Slovenian (CP 1250)'); |
363 | translate_lang_opt('', 'es', 'spa', 'Spanish'); |
364 | translate_lang_opt('', 'sv', 'swe', 'Swedish'); |
365 | translate_lang_opt('', '', 'wel', 'Welsh'); |
366 | ?></SELECT> |
367 | InterTran: <input type=submit value="Translate"> |
368 | <?php |
369 | translate_table_end(); |
370 | } |
371 | |
372 | function translate_form_gpltrans($message) { |
373 | translate_new_form('http://www.translator.cx/cgi-bin/gplTrans'); |
374 | ?><select name="toenglish"><?php |
375 | translate_lang_opt('en', '!en', 'no', 'From English'); |
376 | translate_lang_opt('!en', 'en', 'yes', 'To English'); |
377 | ?></select><select name="language"> |
378 | <?php |
379 | translate_lang_opt('nl', 'nl', 'dutch_dict', 'Dutch'); |
380 | translate_lang_opt('fr', 'fr', 'french_dict', 'French'); |
381 | translate_lang_opt('de', 'de', 'german_dict', 'German'); |
382 | translate_lang_opt('', '', 'indonesian_dict', 'Indonesian'); |
383 | translate_lang_opt('it', 'it', 'italian_dict', 'Italian'); |
384 | translate_lang_opt('', '', 'latin_dict', 'Latin'); |
385 | translate_lang_opt('pt', 'pt', 'portuguese_dict', 'Portuguese'); |
386 | translate_lang_opt('es', 'es', 'spanish_dict', 'Spanish'); |
387 | ?></select> |
388 | <input type="hidden" name="text" value="<?php echo $message ?>"> |
389 | GPLTrans: <input type="submit" value="Translate"> |
390 | <?php |
391 | translate_table_end(); |
392 | } |
393 | |
394 | function translate_form_dictionary($message) { |
395 | translate_new_form('http://translate.dictionary.com:8800/systran/cgi'); |
396 | ?><INPUT TYPE=HIDDEN NAME=partner VALUE=LEXICO> |
397 | <input type=hidden name=urltext value="<?php echo $message ?>"> |
398 | <SELECT NAME="lp"><?php |
399 | translate_lang_opt('en', 'fr', 'en_fr', 'English to French'); |
400 | translate_lang_opt('', 'de', 'en_de', 'English to German'); |
401 | translate_lang_opt('', 'it', 'en_it', 'English to Italian'); |
402 | translate_lang_opt('', 'pt*', 'en_pt', 'English to Portuguese'); |
403 | translate_lang_opt('', 'es', 'en_sp', 'English to Spanish'); |
404 | translate_lang_opt('fr', '', 'fr_en', 'French to English'); |
405 | translate_lang_opt('', '', 'fr_ge', 'French to German'); |
406 | translate_lang_opt('', '', 'ge_fr', 'German to French'); |
407 | translate_lang_opt('de', '', 'de_en', 'German to English'); |
408 | translate_lang_opt('it', '', 'it_en', 'Italian to English'); |
409 | translate_lang_opt('pt*', '', 'pt_en', 'Portuguese to English'); |
410 | translate_lang_opt('es', '', 'sp_en', 'Spanish to English'); |
411 | ?></SELECT> |
412 | Dictionary.com: <INPUT TYPE="submit" VALUE="Translate"> |
413 | <?php |
414 | translate_table_end(); |
415 | } |
416 | ?> |