6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
12 /* Easy plugin that sends the body of the message to a new browser
13 window using the specified translator. It can also translate your
14 outgoing message if you send it to someone in a different country.
16 Languages from i18n, incorporated in the auto-language selection:
18 no - Norwegian (Bokmål)
19 no_NO_ny - Norwegian (Nynorsk)
25 pt_BR - Portuguese (Brazil)
34 /* Initialize the translation plugin */
35 function squirrelmail_plugin_init_translate() {
36 global $squirrelmail_plugin_hooks;
38 $squirrelmail_plugin_hooks['read_body_bottom']['translate'] = 'translate_read_form';
39 $squirrelmail_plugin_hooks['optpage_register_block']['translate'] = 'translate_optpage_register_block';
40 $squirrelmail_plugin_hooks['loading_prefs']['translate'] = 'translate_pref';
41 $squirrelmail_plugin_hooks['compose_button_row']['translate'] = 'translate_button';
45 /* Show the translation for a message you're reading */
46 function translate_read_form() {
47 global $color, $translate_server;
48 global $body, $translate_dir;
49 global $translate_show_read;
51 if (!$translate_show_read) {
55 $translate_dir = 'to';
58 $pos = strpos($new_body,
59 '">'. _("Download this as a file") . '</A></CENTER><BR></SMALL>');
61 $new_body = substr($new_body, 0, $pos);
64 $trans = get_html_translation_table(HTML_ENTITIES
);
65 $trans[' '] = ' ';
66 $trans = array_flip($trans);
67 $new_body = strtr($new_body, $trans);
69 $new_body = urldecode($new_body);
70 $new_body = strip_tags($new_body);
72 /* I really don't like this next part ... */
73 $new_body = str_replace('"', "''", $new_body);
74 $new_body = strtr($new_body, "\n", ' ');
76 $function = 'translate_form_' . $translate_server;
80 function translate_table_end() {
92 function translate_button() {
93 global $translate_show_send;
95 if (! $translate_show_send) {
101 function translate_optpage_register_block() {
102 global $optpage_blocks;
103 $optpage_blocks[] = array(
104 'name' => _("Translation Options"),
105 'url' => '../plugins/translate/options.php',
106 'desc' => _("Which translator should be used when you get messages in a different language?"),
111 function 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;
117 $translate_server = getPref($data_dir, $username, 'translate_server');
118 if ($translate_server == '') {
119 $translate_server = 'babelfish';
122 $translate_location = getPref($data_dir, $username, 'translate_location');
123 if ($translate_location == '') {
124 $translate_location = 'center';
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');
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.
138 function translate_does_it_match_language($test) {
139 global $squirrelmail_language;
145 if (! $test ||
! $squirrelmail_language) {
149 if ($test[$index] == '!') {
155 if (($index == 0) && ($test == $squirrelmail_language)) {
159 while ($test[$index]) {
160 if ($test[$index] == '*') {
163 if ($test[$index] != $squirrelmail_language[$smindex]) {
174 function translate_lang_opt($from, $to, $value, $text) {
175 global $translate_dir;
177 $ret = ' <option value="' . $value . '"';
179 if (translate_does_it_match_language($to) && ($translate_dir == 'to')) {
183 if (translate_does_it_match_language($from) && ($translate_dir == 'from')) {
187 $ret .= '>' . $text . "</option>\n";
193 function translate_new_form($action) {
194 global $translate_dir, $translate_new_window, $translate_location;
195 global $color, $translate_same_window;
197 echo '<form action="';
199 if ($translate_dir == 'to') {
202 echo 'translate.php';
205 echo '" method="post"';
207 if (!$translate_same_window) {
208 echo ' target="_blank"';
213 ?
><table align
="<?php echo $translate_location ?>" cellpadding
=3 cellspacing
=0 border
=0 bgcolor
=<?php
echo $color[10] ?
>>
216 <table cellpadding
=2 cellspacing
=1 border
=0 bgcolor
="<?php echo $color[5] ?>">
221 function translate_form_babelfish($message) {
222 translate_new_form('http://babelfish.altavista.com/translate.dyn');
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
229 echo translate_lang_opt('en', 'fr', 'en_fr',
230 sprintf( _("%s to %s"),
233 translate_lang_opt('', 'de', 'en_de',
234 sprintf( _("%s to %s"),
237 translate_lang_opt('', 'it', 'en_it',
238 sprintf( _("%s to %s"),
241 translate_lang_opt('', 'pt*', 'en_pt',
242 sprintf( _("%s to %s"),
245 translate_lang_opt('', 'es', 'en_es',
246 sprintf( _("%s to %s"),
249 translate_lang_opt('fr', 'en', 'fr_en',
250 sprintf( _("%s to %s"),
253 translate_lang_opt('de', '', 'de_en',
254 sprintf( _("%s to %s"),
257 translate_lang_opt('it', '', 'it_en',
258 sprintf( _("%s to %s"),
261 translate_lang_opt('pt*', '', 'pt_en',
262 sprintf( _("%s to %s"),
265 translate_lang_opt('es', '', 'es_en',
266 sprintf( _("%s to %s"),
269 translate_lang_opt('', '', 'de_fr',
270 sprintf( _("%s to %s"),
273 translate_lang_opt('', '', 'fr_de',
274 sprintf( _("%s to %s"),
277 translate_lang_opt('ru', '', 'ru_en',
278 sprintf( _("%s to %s"),
282 'Babelfish: <input type="Submit" value="' . _("Translate") . '">';
284 translate_table_end();
287 function translate_form_go($message) {
288 translate_new_form('http://translator.go.com/cb/trans_entry');
290 <input type
=hidden name
=input_type value
=text
>
291 <select name
=lp
><?php
292 echo translate_lang_opt('en', 'es', 'en_sp',
293 sprintf( _("%s to %s"),
296 translate_lang_opt('', 'fr', 'en_fr',
297 sprintf( _("%s to %s"),
300 translate_lang_opt('', 'de', 'en_ge',
301 sprintf( _("%s to %s"),
304 translate_lang_opt('', 'it', 'en_it',
305 sprintf( _("%s to %s"),
308 translate_lang_opt('', 'pt', 'en_pt',
309 sprintf( _("%s to %s"),
312 translate_lang_opt('es', 'en', 'sp_en',
313 sprintf( _("%s to %s"),
316 translate_lang_opt('fr', '', 'fr_en',
317 sprintf( _("%s to %s"),
320 translate_lang_opt('de', '', 'ge_en',
321 sprintf( _("%s to %s"),
324 translate_lang_opt('it', '', 'it_en',
325 sprintf( _("%s to %s"),
328 translate_lang_opt('pt', '', 'pt_en',
329 sprintf( _("%s to %s"),
333 "<input type=\"hidden\" name=\"text\" value=\"$message\">".
334 'Go.com: <input type="Submit" value="' . _("Translate") . '">';
336 translate_table_end();
339 function translate_form_intertran($message) {
340 translate_new_form('http://www.tranexp.com:2000/InterTran');
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\">";
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")).
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")).
404 printf( _("%s to %s"), $left, $right );
405 echo 'InterTran: <input type=submit value="' . _("Translate") . '">';
407 translate_table_end();
410 function translate_form_gpltrans($message) {
411 translate_new_form('http://www.translator.cx/cgi-bin/gplTrans');
412 echo '<select name="toenglish">';
413 translate_lang_opt('en', '!en', 'no', 'From English');
414 translate_lang_opt('!en', 'en', 'yes', 'To English');
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")).
425 "<input type=hidden name=text value=\"$message\">".
426 'GPLTrans: <input type="submit" value="' . _("Translate") . '">';
428 translate_table_end();
431 function translate_form_dictionary($message) {
432 translate_new_form('http://translate.dictionary.com:8800/systran/cgi');
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"),
440 translate_lang_opt('', 'de', 'en_de',
441 sprintf( _("%s to %s"),
444 translate_lang_opt('', 'it', 'en_it',
445 sprintf( _("%s to %s"),
448 translate_lang_opt('', 'pt*', 'en_pt',
449 sprintf( _("%s to %s"),
452 translate_lang_opt('', 'es', 'en_sp',
453 sprintf( _("%s to %s"),
456 translate_lang_opt('fr', '', 'fr_en',
457 sprintf( _("%s to %s"),
460 translate_lang_opt('', '', 'fr_ge',
461 sprintf( _("%s to %s"),
464 translate_lang_opt('', '', 'ge_fr',
465 sprintf( _("%s to %s"),
468 translate_lang_opt('de', '', 'de_en',
469 sprintf( _("%s to %s"),
472 translate_lang_opt('it', '', 'it_en',
473 sprintf( _("%s to %s"),
476 translate_lang_opt('pt*', '', 'pt_en',
477 sprintf( _("%s to %s"),
480 translate_lang_opt('es', '', 'sp_en',
481 sprintf( _("%s to %s"),
485 'Dictionary.com: <INPUT TYPE="submit" VALUE="'._("Translate").'">';
487 translate_table_end();