Fix E_ALL notice, thanks Alexandros.
[squirrelmail.git] / plugins / translate / setup.php
index 0a79c35160c871cd5a5ad454a9f2ad678e35f189..927831ae58b1ad59f44a676e95269e03e9ee264b 100644 (file)
@@ -1,5 +1,14 @@
 <?php
 
+/**
+ * setup.php
+ *
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * $Id$
+ */
+
 /* Easy plugin that sends the body of the message to a new browser
 window using the specified translator.  It can also translate your
 outgoing message if you send it to someone in a different country. 
@@ -28,7 +37,6 @@ function squirrelmail_plugin_init_translate() {
 
   $squirrelmail_plugin_hooks['read_body_bottom']['translate'] = 'translate_read_form';
   $squirrelmail_plugin_hooks['optpage_register_block']['translate'] = 'translate_optpage_register_block';
-  $squirrelmail_plugin_hooks['options_save']['translate'] = 'translate_sav';
   $squirrelmail_plugin_hooks['loading_prefs']['translate'] = 'translate_pref';
   $squirrelmail_plugin_hooks['compose_button_row']['translate'] = 'translate_button';
 }
@@ -37,23 +45,36 @@ function squirrelmail_plugin_init_translate() {
 /* Show the translation for a message you're reading */
 function translate_read_form() {
     global $color, $translate_server;
-    global $body, $translate_dir;
+    global $message, $translate_dir;
     global $translate_show_read;
+    global $imapConnection, $wrap_at, $passed_id, $mailbox;
 
     if (!$translate_show_read) {
         return;
     }
     
     $translate_dir = 'to';
-            
+
+$trans_ar = $message->findDisplayEntity(array(), array('text/plain'));
+$body = '';
+if ($trans_ar[0] != '') {
+  for ($i = 0; $i < count($trans_ar); $i++) {
+    $body .= formatBody($imapConnection, $message, $color, $wrap_at, $trans_ar[$i], $passed_id, $mailbox);
+  }
+    $hookResults = do_hook('message_body', $body);
+    $body = $hookResults[1];
+  } else {
+    $body = 'Message can\'t be translated';
+}
+
     $new_body = $body;
     $pos = strpos($new_body,
-            '">Download this as a file</A></CENTER><BR></SMALL>');
+            '">'. _("Download this as a file") . '</A></CENTER><BR></SMALL>');
     if (is_int($pos)) {
         $new_body = substr($new_body, 0, $pos);
     }
-                     
-    $trans = get_html_translation_table('HTMLENTITIES');
+
+    $trans = get_html_translation_table(HTML_ENTITIES);
     $trans[' '] = '&nbsp;';
     $trans = array_flip($trans);
     $new_body = strtr($new_body, $trans);
@@ -100,50 +121,6 @@ function translate_optpage_register_block() {
     );
 }
 
-function translate_sav() {
-    global $username,$data_dir;
-    global $submit_translate, $translate_translate_server;
-    global $translate_translate_location;
-    global $translate_translate_show_read;
-    global $translate_translate_show_send;
-    global $translate_translate_same_window;
-  
-    if ($submit_translate) {
-        if (isset($translate_translate_server)) {
-            setPref($data_dir, $username, 'translate_server', $translate_translate_server);
-        } else {
-            setPref($data_dir, $username, 'translate_server', 'babelfish');
-        }
-
-        if (isset($translate_translate_location)) {
-            setPref($data_dir, $username, 'translate_location', $translate_translate_location);
-        } else {
-            setPref($data_dir, $username, 'translate_location', 'center');
-        }
-
-        if (isset($translate_translate_show_read)) {
-            setPref($data_dir, $username, 'translate_show_read', '1');
-        } else {
-            setPref($data_dir, $username, 'translate_show_read', '');
-        }
-
-        if (isset($translate_translate_show_send)) {
-            setPref($data_dir, $username, 'translate_show_send', '1');
-        } else {
-            setPref($data_dir, $username, 'translate_show_send', '');
-        }
-
-        if (isset($translate_translate_same_window)) {
-           setPref($data_dir, $username, 'translate_same_window', '1');
-        } else {
-            setPref($data_dir, $username, 'translate_same_window', '');
-        }
-
-        echo '<center>Translation options saved.</center>';
-    }
-}
-
-
 function translate_pref() { 
     global $username, $data_dir;
     global $translate_server, $translate_location;
@@ -192,7 +169,7 @@ function translate_does_it_match_language($test) {
         return $true;
     }
       
-    while ($test[$index]) {
+    while (isset($test[$index]) && $test[$index]) {
         if ($test[$index] == '*') {
             return $true;
         }
@@ -255,14 +232,18 @@ function translate_new_form($action) {
 }
 
 function translate_form_babelfish($message) {
-    translate_new_form('http://babelfish.altavista.com/translate.dyn');
+    translate_new_form('http://babelfish.altavista.com/babelfish/tr');
 ?>
     <input type="hidden" name="doit" value="done">
-    <input type="hidden" name="BabelFishFrontPage" value="yes">
-    <input type="hidden" name="bblType" value="urltext">
+    <input type="hidden" name="intl" value="1">
+    <input type="hidden" name="tt" value="urltext">
     <input type="hidden" name="urltext" value="<?php echo $message; ?>">
     <select name="lp"><?php
-        echo translate_lang_opt('en',  'fr',  'en_fr',
+        echo translate_lang_opt('en',  'zh',  'en_zh',
+                                sprintf( _("%s to %s"),
+                                         _("English"),
+                                         _("Chinese"))) .
+            translate_lang_opt('en',  'fr',  'en_fr',
                                 sprintf( _("%s to %s"),
                                          _("English"),
                                          _("French"))) .
@@ -274,6 +255,14 @@ function translate_form_babelfish($message) {
                                 sprintf( _("%s to %s"),
                                          _("English"),
                                          _("Italian"))) .
+            translate_lang_opt('en',  'ja',  'en_ja',
+                                sprintf( _("%s to %s"),
+                                         _("English"),
+                                         _("Japanese"))) .
+            translate_lang_opt('en',  'ko',  'en_ko',
+                                sprintf( _("%s to %s"),
+                                         _("English"),
+                                         _("Korean"))) .
              translate_lang_opt('',    'pt*', 'en_pt',
                                 sprintf( _("%s to %s"),
                                          _("English"),
@@ -282,6 +271,10 @@ function translate_form_babelfish($message) {
                                 sprintf( _("%s to %s"),
                                          _("English"),
                                          _("Spanish"))) .
+             translate_lang_opt('zh',  'en',  'zh_en',
+                                sprintf( _("%s to %s"),
+                                         _("Chinese"),
+                                         _("English"))) .
              translate_lang_opt('fr',  'en',  'fr_en',
                                 sprintf( _("%s to %s"),
                                          _("French"),
@@ -294,6 +287,14 @@ function translate_form_babelfish($message) {
                                 sprintf( _("%s to %s"),
                                          _("Italian"),
                                          _("English"))) .
+             translate_lang_opt('ja',  'en',  'ja_en',
+                                sprintf( _("%s to %s"),
+                                         _("Japanese"),
+                                         _("English"))) .
+             translate_lang_opt('ko',  'en',  'ko_en',
+                                sprintf( _("%s to %s"),
+                                         _("Korean"),
+                                         _("English"))) .
              translate_lang_opt('pt*', '',    'pt_en',
                                 sprintf( _("%s to %s"),
                                          _("Portuguese"),
@@ -405,6 +406,7 @@ function translate_form_intertran($message) {
         translate_lang_opt('',      '',    'slo', _("Slovenian") . ' (CP 1250)').
         translate_lang_opt('es',    '',    'spa', _("Spanish")).
         translate_lang_opt('sv',    '',    'swe', _("Swedish")).
+        translate_lang_opt('',      '',    'tur', _("Turkish") . ' (CP 1254)').
         translate_lang_opt('',      '',    'wel', _("Welsh")).
         '</SELECT>';
 
@@ -435,6 +437,7 @@ function translate_form_intertran($message) {
         translate_lang_opt('',    '',      'slo', _("Slovenian") . ' (CP 1250)').
         translate_lang_opt('',    'es',    'spa', _("Spanish")).
         translate_lang_opt('',    'sv',    'swe', _("Swedish")).
+        translate_lang_opt('',      '',    'tur', _("Turkish") . ' (CP 1254)').
         translate_lang_opt('',    '',      'wel', _("Welsh")).
         '</SELECT>';
     printf( _("%s to %s"), $left, $right );
@@ -445,10 +448,7 @@ function translate_form_intertran($message) {
 
 function translate_form_gpltrans($message) {
     translate_new_form('http://www.translator.cx/cgi-bin/gplTrans');
-    echo '<select name="toenglish">';
-    translate_lang_opt('en',  '!en', 'no',  'From English');
-    translate_lang_opt('!en', 'en',  'yes', 'To English');
-    echo '</select><select name="language">'.
+    echo '<select name="language">'.
         translate_lang_opt('nl', 'nl', 'dutch_dict',      _("Dutch")).
         translate_lang_opt('fr', 'fr', 'french_dict',     _("French")).
         translate_lang_opt('de', 'de', 'german_dict',     _("German")).
@@ -457,23 +457,28 @@ function translate_form_gpltrans($message) {
         translate_lang_opt('',   '',   'latin_dict',      _("Latin")).
         translate_lang_opt('pt', 'pt', 'portuguese_dict', _("Portuguese")).
         translate_lang_opt('es', 'es', 'spanish_dict',    _("Spanish")).
-        '</select>'.
-        "<input type=hidden name=text value=\"$message\">".
+        '</select>';
+    echo '<select name="toenglish">';
+    echo '<option value="yes" >'. _("to English") . '</option>';
+    echo '<option value="no" selected>' . _("from English") . '</option></select>';
+    echo "<input type=hidden name=text value=\"$message\">".
         'GPLTrans: <input type="submit" value="' . _("Translate") . '">';
 
     translate_table_end();
 }
 
 function translate_form_dictionary($message) {
-    translate_new_form('http://translate.dictionary.com:8800/systran/cgi');
-    echo '<INPUT TYPE=HIDDEN NAME=partner VALUE=LEXICO>'.
-         "<input type=hidden name=urltext value=\"$message\">".
+    translate_new_form('http://dictionary.reference.com/translate/text.html');
+    list($usec, $sec) = explode(" ",microtime());
+    $time = $sec . (float)$usec*100000000;
+    echo "<input type=hidden name=text value=\"$message\">".
+         "<input type=hidden name=r value=\"$time\">".
          '<SELECT NAME="lp">'.
          translate_lang_opt('en',  'fr', 'en_fr',
                             sprintf( _("%s to %s"),
                                      _("English"),
                                      _("French"))) .
-         translate_lang_opt('',    'de', 'en_de',
+         translate_lang_opt('',    'ge', 'en_ge',
                             sprintf( _("%s to %s"),
                                      _("English"),
                                      _("German"))) .
@@ -485,7 +490,7 @@ function translate_form_dictionary($message) {
                             sprintf( _("%s to %s"),
                                      _("English"),
                                      _("Portuguese"))) .
-         translate_lang_opt('',    'es', 'en_sp',
+         translate_lang_opt('',    'es', 'en_es',
                             sprintf( _("%s to %s"),
                                      _("English"),
                                      _("Spanish"))) .
@@ -501,7 +506,7 @@ function translate_form_dictionary($message) {
                             sprintf( _("%s to %s"),
                                      _("German"),
                                      _("French"))) .
-         translate_lang_opt('de',  '', 'de_en',
+         translate_lang_opt('de',  '', 'ge_en',
                             sprintf( _("%s to %s"),
                                      _("German"),
                                      _("English"))) .
@@ -513,11 +518,11 @@ function translate_form_dictionary($message) {
                             sprintf( _("%s to %s"),
                                      _("Portuguese"),
                                      _("English"))) .
-         translate_lang_opt('es',  '', 'sp_en',
+         translate_lang_opt('es',  '', 'es_en',
                             sprintf( _("%s to %s"),
                                      _("Spanish"),
                                      _("English"))) .
-         '<\SELECT>'.
+         '</SELECT>'.
          'Dictionary.com: <INPUT TYPE="submit" VALUE="'._("Translate").'">';
 
   translate_table_end();