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