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.
7 Languages from i18n, incorporated in the auto-language selection:
9 no - Norwegian (Bokmål)
10 no_NO_ny - Norwegian (Nynorsk)
16 pt_BR - Portuguese (Brazil)
25 /* Initialize the translation plugin */
26 function squirrelmail_plugin_init_translate() {
27 global $squirrelmail_plugin_hooks;
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';
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;
43 if (!$translate_show_read) {
47 $translate_dir = 'to';
50 $pos = strpos($new_body,
51 '">Download this as a file</A></CENTER><BR></SMALL>');
53 $new_body = substr($new_body, 0, $pos);
56 $trans = get_html_translation_table('HTMLENTITIES');
57 $trans[' '] = ' ';
58 $trans = array_flip($trans);
59 $new_body = strtr($new_body, $trans);
61 $new_body = urldecode($new_body);
62 $new_body = strip_tags($new_body);
64 /* I really don't like this next part ... */
65 $new_body = str_replace('"', "''", $new_body);
66 $new_body = strtr($new_body, "\n", ' ');
68 $function = 'translate_form_' . $translate_server;
72 function translate_table_end() {
84 function translate_button() {
85 global $translate_show_send;
87 if (! $translate_show_send) {
93 function translate_opt() {
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?"),
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;
111 if ($submit_translate) {
112 if (isset($translate_translate_server)) {
113 setPref($data_dir, $username, 'translate_server', $translate_translate_server);
115 setPref($data_dir, $username, 'translate_server', 'babelfish');
118 if (isset($translate_translate_location)) {
119 setPref($data_dir, $username, 'translate_location', $translate_translate_location);
121 setPref($data_dir, $username, 'translate_location', 'center');
124 if (isset($translate_translate_show_read)) {
125 setPref($data_dir, $username, 'translate_show_read', '1');
127 setPref($data_dir, $username, 'translate_show_read', '');
130 if (isset($translate_translate_show_send)) {
131 setPref($data_dir, $username, 'translate_show_send', '1');
133 setPref($data_dir, $username, 'translate_show_send', '');
136 if (isset($translate_translate_same_window)) {
137 setPref($data_dir, $username, 'translate_same_window', '1');
139 setPref($data_dir, $username, 'translate_same_window', '');
142 echo '<center>Translation options saved.</center>';
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;
153 $translate_server = getPref($data_dir, $username, 'translate_server');
154 if ($translate_server == '') {
155 $translate_server = 'babelfish';
158 $translate_location = getPref($data_dir, $username, 'translate_location');
159 if ($translate_location == '') {
160 $translate_location = 'center';
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');
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.
174 function translate_does_it_match_language($test) {
175 global $squirrelmail_language;
181 if (! $test ||
! $squirrelmail_language) {
185 if ($test[$index] == '!') {
191 if (($index == 0) && ($test == $squirrelmail_language)) {
195 while ($test[$index]) {
196 if ($test[$index] == '*') {
199 if ($test[$index] != $squirrelmail_language[$smindex]) {
210 function translate_lang_opt($from, $to, $value, $text) {
211 global $translate_dir;
213 $ret = ' <option value="' . $value . '"';
215 if (translate_does_it_match_language($to) && ($translate_dir == 'to')) {
219 if (translate_does_it_match_language($from) && ($translate_dir == 'from')) {
223 $ret .= '>' . $text . "</option>\n";
229 function translate_new_form($action) {
230 global $translate_dir, $translate_new_window, $translate_location;
231 global $color, $translate_same_window;
233 echo '<form action="';
235 if ($translate_dir == 'to') {
238 echo 'translate.php';
241 echo '" method="post"';
243 if (!$translate_same_window) {
244 echo ' target="_blank"';
249 ?
><table align
="<?php echo $translate_location ?>" cellpadding
=3 cellspacing
=0 border
=0 bgcolor
=<?php
echo $color[10] ?
>>
252 <table cellpadding
=2 cellspacing
=1 border
=0 bgcolor
="<?php echo $color[5] ?>">
257 function translate_form_babelfish($message) {
258 translate_new_form('http://babelfish.altavista.com/translate.dyn');
260 <input type
="hidden" name
="doit" value
="done">
261 <input type
="hidden" name
="BabelFishFrontPage" value
="yes">
262 <input type
="hidden" name
="bblType" value
="urltext">
263 <input type
="hidden" name
="urltext" value
="<?php echo $message; ?>">
264 <select name
="lp"><?php
265 echo translate_lang_opt('en', 'fr', 'en_fr',
266 sprintf( _("%s to %s"),
269 translate_lang_opt('', 'de', 'en_de',
270 sprintf( _("%s to %s"),
273 translate_lang_opt('', 'it', 'en_it',
274 sprintf( _("%s to %s"),
277 translate_lang_opt('', 'pt*', 'en_pt',
278 sprintf( _("%s to %s"),
281 translate_lang_opt('', 'es', 'en_es',
282 sprintf( _("%s to %s"),
285 translate_lang_opt('fr', 'en', 'fr_en',
286 sprintf( _("%s to %s"),
289 translate_lang_opt('de', '', 'de_en',
290 sprintf( _("%s to %s"),
293 translate_lang_opt('it', '', 'it_en',
294 sprintf( _("%s to %s"),
297 translate_lang_opt('pt*', '', 'pt_en',
298 sprintf( _("%s to %s"),
301 translate_lang_opt('es', '', 'es_en',
302 sprintf( _("%s to %s"),
305 translate_lang_opt('', '', 'de_fr',
306 sprintf( _("%s to %s"),
309 translate_lang_opt('', '', 'fr_de',
310 sprintf( _("%s to %s"),
313 translate_lang_opt('ru', '', 'ru_en',
314 sprintf( _("%s to %s"),
318 'Babelfish: <input type="Submit" value="' . _("Translate") . '">';
320 translate_table_end();
323 function translate_form_go($message) {
324 translate_new_form('http://translator.go.com/cb/trans_entry');
326 <input type
=hidden name
=input_type value
=text
>
327 <select name
=lp
><?php
328 echo translate_lang_opt('en', 'es', 'en_sp',
329 sprintf( _("%s to %s"),
332 translate_lang_opt('', 'fr', 'en_fr',
333 sprintf( _("%s to %s"),
336 translate_lang_opt('', 'de', 'en_ge',
337 sprintf( _("%s to %s"),
340 translate_lang_opt('', 'it', 'en_it',
341 sprintf( _("%s to %s"),
344 translate_lang_opt('', 'pt', 'en_pt',
345 sprintf( _("%s to %s"),
348 translate_lang_opt('es', 'en', 'sp_en',
349 sprintf( _("%s to %s"),
352 translate_lang_opt('fr', '', 'fr_en',
353 sprintf( _("%s to %s"),
356 translate_lang_opt('de', '', 'ge_en',
357 sprintf( _("%s to %s"),
360 translate_lang_opt('it', '', 'it_en',
361 sprintf( _("%s to %s"),
364 translate_lang_opt('pt', '', 'pt_en',
365 sprintf( _("%s to %s"),
369 "<input type=\"hidden\" name=\"text\" value=\"$message\">".
370 'Go.com: <input type="Submit" value="' . _("Translate") . '">';
372 translate_table_end();
375 function translate_form_intertran($message) {
376 translate_new_form('http://www.tranexp.com:2000/InterTran');
377 echo '<INPUT TYPE="hidden" NAME="topframe" VALUE="yes">'.
378 '<INPUT TYPE="hidden" NAME="type" VALUE="text">'.
379 "<input type=\"hidden\" name=\"text\" value=\"$message\">";
381 $left = '<SELECT name="from">' .
382 translate_lang_opt('pt_BR', '', 'pob', _("Brazilian Portuguese")).
383 translate_lang_opt('', '', 'bul', _("Bulgarian") . ' (CP 1251)').
384 translate_lang_opt('', '', 'cro', _("Croatian") . ' (CP 1250)').
385 translate_lang_opt('cs', '', 'che', _("Czech") . ' (CP 1250)').
386 translate_lang_opt('', '', 'dan', _("Danish")).
387 translate_lang_opt('nl', '', 'dut', _("Dutch")).
388 translate_lang_opt('en', '!en', 'eng', _("English")).
389 translate_lang_opt('', '', 'spe', _("European Spanish")).
390 translate_lang_opt('', '', 'fin', _("Finnish")).
391 translate_lang_opt('fr', '', 'fre', _("French")).
392 translate_lang_opt('de', '', 'ger', _("German")).
393 translate_lang_opt('', '', 'grk', _("Greek")).
394 translate_lang_opt('', '', 'hun', _("Hungarian") . ' (CP 1250)').
395 translate_lang_opt('', '', 'ice', _("Icelandic")).
396 translate_lang_opt('it', '', 'ita', _("Italian")).
397 translate_lang_opt('', '', 'jpn', _("Japanese") . ' (Shift JIS)').
398 translate_lang_opt('', '', 'spl', _("Latin American Spanish")).
399 translate_lang_opt('no*', '', 'nor', _("Norwegian")).
400 translate_lang_opt('pl', '', 'pol', _("Polish") . ' (ISO 8859-2)').
401 translate_lang_opt('', '', 'poe', _("Portuguese")).
402 translate_lang_opt('', '', 'rom', _("Romanian") . ' (CP 1250)').
403 translate_lang_opt('ru', '', 'rus', _("Russian") . ' (CP 1251)').
404 translate_lang_opt('', '', 'sel', _("Serbian") . ' (CP 1250)').
405 translate_lang_opt('', '', 'slo', _("Slovenian") . ' (CP 1250)').
406 translate_lang_opt('es', '', 'spa', _("Spanish")).
407 translate_lang_opt('sv', '', 'swe', _("Swedish")).
408 translate_lang_opt('', '', 'wel', _("Welsh")).
411 $right = '<SELECT name="to">'.
412 translate_lang_opt('', 'pt_BR', 'pob', _("Brazilian Portuguese")).
413 translate_lang_opt('', '', 'bul', _("Bulgarian") . ' (CP 1251)').
414 translate_lang_opt('', '', 'cro', _("Croatian") . ' (CP 1250)').
415 translate_lang_opt('', 'cs', 'che', _("Czech") . ' (CP 1250)').
416 translate_lang_opt('', '', 'dan', _("Danish")).
417 translate_lang_opt('', 'nl', 'dut', _("Dutch")).
418 translate_lang_opt('!en', 'en', 'eng', _("English")).
419 translate_lang_opt('', '', 'spe', _("European Spanish")).
420 translate_lang_opt('', '', 'fin', _("Finnish")).
421 translate_lang_opt('', 'fr', 'fre', _("French")).
422 translate_lang_opt('', 'de', 'ger', _("German")).
423 translate_lang_opt('', '', 'grk', _("Greek")).
424 translate_lang_opt('', '', 'hun', _("Hungarian") . ' (CP 1250)').
425 translate_lang_opt('', '', 'ice', _("Icelandic")).
426 translate_lang_opt('', 'it', 'ita', _("Italian")).
427 translate_lang_opt('', '', 'jpn', _("Japanese") . ' (Shift JIS)').
428 translate_lang_opt('', '', 'spl', _("Latin American Spanish")).
429 translate_lang_opt('', 'no*', 'nor', _("Norwegian")).
430 translate_lang_opt('', 'pl', 'pol', _("Polish") . ' (ISO 8859-2)').
431 translate_lang_opt('', '', 'poe', _("Portuguese")).
432 translate_lang_opt('', '', 'rom', _("Romanian") . ' (CP 1250)').
433 translate_lang_opt('', 'ru', 'rus', _("Russian") . ' (CP 1251)').
434 translate_lang_opt('', '', 'sel', _("Serbian") . ' (CP 1250)').
435 translate_lang_opt('', '', 'slo', _("Slovenian") . ' (CP 1250)').
436 translate_lang_opt('', 'es', 'spa', _("Spanish")).
437 translate_lang_opt('', 'sv', 'swe', _("Swedish")).
438 translate_lang_opt('', '', 'wel', _("Welsh")).
440 printf( _("%s to %s"), $left, $right );
441 echo 'InterTran: <input type=submit value="' . _("Translate") . '">';
443 translate_table_end();
446 function translate_form_gpltrans($message) {
447 translate_new_form('http://www.translator.cx/cgi-bin/gplTrans');
448 echo '<select name="toenglish">';
449 translate_lang_opt('en', '!en', 'no', 'From English');
450 translate_lang_opt('!en', 'en', 'yes', 'To English');
451 echo '</select><select name="language">'.
452 translate_lang_opt('nl', 'nl', 'dutch_dict', _("Dutch")).
453 translate_lang_opt('fr', 'fr', 'french_dict', _("French")).
454 translate_lang_opt('de', 'de', 'german_dict', _("German")).
455 translate_lang_opt('', '', 'indonesian_dict', _("Indonesian")).
456 translate_lang_opt('it', 'it', 'italian_dict', _("Italian")).
457 translate_lang_opt('', '', 'latin_dict', _("Latin")).
458 translate_lang_opt('pt', 'pt', 'portuguese_dict', _("Portuguese")).
459 translate_lang_opt('es', 'es', 'spanish_dict', _("Spanish")).
461 "<input type=hidden name=text value=\"$message\">".
462 'GPLTrans: <input type="submit" value="' . _("Translate") . '">';
464 translate_table_end();
467 function translate_form_dictionary($message) {
468 translate_new_form('http://translate.dictionary.com:8800/systran/cgi');
469 echo '<INPUT TYPE=HIDDEN NAME=partner VALUE=LEXICO>'.
470 "<input type=hidden name=urltext value=\"$message\">".
471 '<SELECT NAME="lp">'.
472 translate_lang_opt('en', 'fr', 'en_fr',
473 sprintf( _("%s to %s"),
476 translate_lang_opt('', 'de', 'en_de',
477 sprintf( _("%s to %s"),
480 translate_lang_opt('', 'it', 'en_it',
481 sprintf( _("%s to %s"),
484 translate_lang_opt('', 'pt*', 'en_pt',
485 sprintf( _("%s to %s"),
488 translate_lang_opt('', 'es', 'en_sp',
489 sprintf( _("%s to %s"),
492 translate_lang_opt('fr', '', 'fr_en',
493 sprintf( _("%s to %s"),
496 translate_lang_opt('', '', 'fr_ge',
497 sprintf( _("%s to %s"),
500 translate_lang_opt('', '', 'ge_fr',
501 sprintf( _("%s to %s"),
504 translate_lang_opt('de', '', 'de_en',
505 sprintf( _("%s to %s"),
508 translate_lang_opt('it', '', 'it_en',
509 sprintf( _("%s to %s"),
512 translate_lang_opt('pt*', '', 'pt_en',
513 sprintf( _("%s to %s"),
516 translate_lang_opt('es', '', 'sp_en',
517 sprintf( _("%s to %s"),
521 'Dictionary.com: <INPUT TYPE="submit" VALUE="'._("Translate").'">';
523 translate_table_end();