From 20bc790c3c11aa52113b5f8ec18fd0c5d974e122 Mon Sep 17 00:00:00 2001 From: tokul Date: Fri, 15 Oct 2004 10:59:14 +0000 Subject: [PATCH] dumping translate plugin changes into cvs. * moved all functions to functions.php * added site configuration options * added custom translation engine options translation engines still need some updates that will be added later git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8185 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/translate/README | 1 + plugins/translate/config_default.php | 95 +++ plugins/translate/functions.php | 827 +++++++++++++++++++++++++++ plugins/translate/index.php | 31 +- plugins/translate/options.php | 144 ++--- plugins/translate/setup.php | 662 +-------------------- 6 files changed, 1001 insertions(+), 759 deletions(-) create mode 100644 plugins/translate/config_default.php create mode 100644 plugins/translate/functions.php diff --git a/plugins/translate/README b/plugins/translate/README index 0fc6e7c7..fc271577 100644 --- a/plugins/translate/README +++ b/plugins/translate/README @@ -58,6 +58,7 @@ Questions/comments/flames/etc can be sent to the Squirrelmail Plugins list Changes ======= + * Plugin included into squirrelmail distribution 1.3 -> 1.4 * Modified to use new option page hook. Paul Joseph Thompson diff --git a/plugins/translate/config_default.php b/plugins/translate/config_default.php new file mode 100644 index 00000000..97edc21b --- /dev/null +++ b/plugins/translate/config_default.php @@ -0,0 +1,95 @@ + \ No newline at end of file diff --git a/plugins/translate/functions.php b/plugins/translate/functions.php new file mode 100644 index 00000000..2c3a96bd --- /dev/null +++ b/plugins/translate/functions.php @@ -0,0 +1,827 @@ +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") . '
'); + if (is_int($pos)) { + $new_body = substr($new_body, 0, $pos); + } + + $trans = get_html_translation_table(HTML_ENTITIES); + $trans[' '] = ' '; + $trans = array_flip($trans); + $new_body = strtr($new_body, $trans); + + $new_body = urldecode($new_body); + $new_body = strip_tags($new_body); + + /* I really don't like this next part ... */ + $new_body = str_replace('"', "''", $new_body); + $new_body = strtr($new_body, "\n", ' '); + + $function = 'translate_form_' . $translate_server; + $function($new_body); +} + +/** + * Adds translation option block + * @access private + */ +function translate_optpage_function() { + global $optpage_blocks; + $optpage_blocks[] = array( + 'name' => _("Translation Options"), + 'url' => '../plugins/translate/options.php', + 'desc' => _("Which translator should be used when you get messages in a different language?"), + 'js' => false + ); +} + +/** + * Gets user's translation preferences + * @access private + */ +function translate_pref_function() { + global $username, $data_dir; + global $translate_server, $translate_location; + global $translate_show_send, $translate_show_read; + global $translate_same_window,$translate_default_engine; + + $translate_server = getPref($data_dir, $username, 'translate_server',$translate_default_engine); + + $translate_location = getPref($data_dir, $username, 'translate_location'); + if ($translate_location == '') { + $translate_location = 'center'; + } + + $translate_show_send = getPref($data_dir, $username, 'translate_show_send'); + $translate_show_read = getPref($data_dir, $username, 'translate_show_read'); + $translate_same_window = getPref($data_dir, $username, 'translate_same_window'); +} + +/** + * Should add translation options in compose window + * + * Unimplemented + * @access private + */ +function translate_button_function() { + global $translate_show_send; + + if (! $translate_show_send) { + return; + } +} + +/** Option functions */ + +/** + * + */ +function translate_showoption() { + global $translate_babelfish_enabled, $translate_go_enabled, + $translate_dictionary_enabled, $translate_google_enabled, + $translate_gpltrans_enabled, $translate_intertran_enabled, + $translate_promt_enabled, $translate_otenet_enabled; + global $translate_custom_enabled; + + if ($translate_babelfish_enabled) translate_showoption_internal('server','babelfish', 'Babelfish'); + if ($translate_go_enabled) translate_showoption_internal('server','go', 'Go.com'); + if ($translate_dictionary_enabled) translate_showoption_internal('server','dictionary', 'Dictionary.com'); + if ($translate_google_enabled) translate_showoption_internal('server','google', 'Google Translate'); + if ($translate_gpltrans_enabled && $translate_gpltrans_url!='') + translate_showoption_internal('server','gpltrans', 'GPLTrans'); + if ($translate_intertran_enabled) translate_showoption_internal('server','intertran', 'Intertran'); + if ($translate_otenet_enabled) translate_showoption_internal('server','otenet', 'OTEnet'); + if ($translate_promt_enabled) translate_showoption_internal('server','promt', 'PROMT'); + if ($translate_custom_enabled && function_exists('translate_custom_showoption')) { + translate_custom_showoption(); + } +} + +/** + * + */ +function translate_showtrad() { + global $translate_babelfish_enabled, $translate_go_enabled, + $translate_dictionary_enabled, $translate_google_enabled, + $translate_gpltrans_enabled, $translate_intertran_enabled, + $translate_promt_enabled, $translate_otenet_enabled; + global $translate_gpltrans_url, $translate_custom_enabled; + + if ($translate_babelfish_enabled) translate_showtrad_internal( 'Babelfish', + _("Maximum of 1000 characters translated, powered by Systran"). + "
".sprintf(_("Number of supported language pairs: %s"),"19")." " , + 'http://babelfish.altavista.com/' ); + if ($translate_go_enabled) translate_showtrad_internal( 'Translator.Go.com', + _("Maximum of 25 kilobytes translated, powered by Systran"). + "
".sprintf(_("Number of supported language pairs: %s"),"10")." " , + 'http://translator.go.com/' ); + if ($translate_dictionary_enabled) translate_showtrad_internal( 'Dictionary.com', + _("No known limits, powered by Systran"). + "
".sprintf(_("Number of supported language pairs: %s"),"24")." " , + 'http://www.dictionary.com/translate' ); + if ($translate_google_enabled) translate_showtrad_internal( 'Google Translate', + _("No known limits, powered by Systran"). + "
".sprintf(_("Number of supported language pairs: %s"),"12")." " , + 'http://www.google.com/translate' ); + if ($translate_gpltrans_enabled && $translate_gpltrans_url!='') translate_showtrad_internal( 'GPLTrans', + _("No known limits, powered by GPLTrans (free, open source)"). + "
".sprintf(_("Number of supported language pairs: %s"),"16")." " , + 'http://www.translator.cx/' ); + if ($translate_intertran_enabled) translate_showtrad_internal( 'InterTran', + _("No known limits, powered by Translation Experts' InterTran"). + "
".sprintf(_("Number of supported languages: %s"),"29")." " , + 'http://www.tranexp.com/' ); + if ($translate_otenet_enabled) translate_showtrad_internal( 'OTEnet', + _("Hellenic translations, no known limits, powered by Systran"). + "
".sprintf(_("Number of supported language pairs: %s"),"20")." " , + 'http://systran.otenet.gr/' ); + if ($translate_promt_enabled) translate_showtrad_internal( 'PROMT', + _("Russian translations, maximum of 500 characters translated"). + "
".sprintf(_("Number of supported language pairs: %s"),"13")." " , + 'http://www.online-translator.com/' ); + + if ($translate_custom_enabled && function_exists('translate_custom_showtrad')) { + translate_custom_showtrad(); + } +} + +/** + * Creates options for translation selection boxes + * @param string $Var option type (server,location) + * @param string $value option value + * @param string $Desc description of translation server + * @access private + * @since 1.5.1 + */ +function translate_showoption_internal($Var,$value, $Desc) { + $Var='translate_' . $Var; + + global $$Var; + + echo '\n"; +} + +/** + * Creates translation server description + * @param string $tit title + * @param string $com comments about translation server + * @param string $url url of translation server + * @access private + */ +function translate_showtrad_internal( $tit, $com, $url ) { + echo "
  • $tit - ". + $com . + "[ $tit ]
  • "; +} + +/** Internal functions */ + +/** + * Closes table tags in translation box + * @access private + */ +function translate_table_end() { + ?> + + + + + + + ' . $text . "\n"; + + return( $ret ); +} + +/** + * Starts translation box + * + * @param string $action url that has to recieve message for translation + * @access private + */ +function translate_new_form($action) { + global $translate_dir, $translate_new_window, $translate_location; + global $color, $translate_same_window; + + echo '
    \n"; + + ?>> + + - -
    + + + '. '' . + ''.html_tag('td',_("When reading:"),'right','','nowrap'). + '\n"; - ShowOption('server', 'babelfish', 'Babelfish'); -// ShowOption('server', 'go', 'Go.com'); - ShowOption('server', 'dictionary', 'Dictionary.com'); - ShowOption('server', 'google', 'Google Translate'); - ShowOption('server', 'gpltrans', 'GPLTrans'); - ShowOption('server', 'intertran', 'Intertran'); - ShowOption('server', 'otenet', 'OTEnet'); - ShowOption('server', 'promt', 'PROMT'); - echo '' . - '' . - ''.html_tag('td',_("When reading:"),'right','','nowrap'). - '\n"; - -$disable_compose_translate=true; if (!$disable_compose_translate) { echo ''.html_tag('td',_("When composing:"),'right','','nowrap'). ' - -
    + + + + + '; + + translate_table_end(); +} + +/** + * go.com translation engine (disabled) + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_go($message) { + translate_new_form('http://translator.go.com/cb/trans_entry'); +?> + + '. + 'Go.com: '; + + translate_table_end(); +} + +/** + * intertran translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_intertran($message) { + translate_new_form('http://www.tranexp.com:2000/InterTran'); + echo ''. + ''. + ''; + + $left = ''; + + $right = ''; + printf( _("%s to %s"), $left, $right ); + echo 'InterTran: '; + + translate_table_end(); +} + +/** + * gpltrans translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_gpltrans($message) { + translate_new_form('http://www.translator.cx/cgi-bin/gplTrans'); + echo ''; + echo ''; + echo ''. + 'GPLTrans: '; + + translate_table_end(); +} + +/** + * reference.com (dictionary) translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_dictionary($message) { + translate_new_form('http://dictionary.reference.com/translate/text.html'); + list($usec, $sec) = explode(" ",microtime()); + $time = $sec . (float)$usec*100000000; + echo ''. + ''. + ''. + 'Dictionary.com: '; + + translate_table_end(); +} + +/** + * otenet translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_otenet($message) { + translate_new_form('http://systran.otenet.gr/cgi-bin/systran.cgi'); +?> + + + + '; + + translate_table_end(); +} + +/** + * promt translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_promt($message) { + translate_new_form('http://www.online-translator.com/text.asp#tr_form'); + echo ''; + echo ''; + echo _("Interface language")." : "; + echo "
    \n"; + echo _("Translation direction")." : "; + echo '
    \n"; + echo "\n"; + echo 'PROMT: '; + + translate_table_end(); +} + +/** + * google translation engine + * + * @param string $message text that has to be translated + * @access private + */ +function translate_form_google($message) { + translate_new_form('http://www.google.com/translate_t'); +?> + + + + + '; + + translate_table_end(); +} +?> \ No newline at end of file diff --git a/plugins/translate/index.php b/plugins/translate/index.php index 4e27ca01..9befff83 100644 --- a/plugins/translate/index.php +++ b/plugins/translate/index.php @@ -1,19 +1,16 @@ diff --git a/plugins/translate/options.php b/plugins/translate/options.php index f8e2c534..faaff93a 100644 --- a/plugins/translate/options.php +++ b/plugins/translate/options.php @@ -1,5 +1,4 @@ ' . $Desc . "\n"; -} - -/** - * FIXME: undocumented function - * @access private - */ -function ShowTrad( $tit, $com, $url ) { - - echo "
  • $tit - ". - $com . - "[ $tit ]
  • "; - -} ?>
    -

    "._("Saved Translation Options")."

    \n"; }?> @@ -114,37 +83,7 @@ function ShowTrad( $tit, $com, $url ) {
      ".sprintf(_("Number of supported language pairs: %s"),"19")." " , - 'http://babelfish.altavista.com/' ); -// ShowTrad( 'Translator.Go.com', -// _("10 language pairs, maximum of 25 kilobytes translated, powered by Systran"), -// 'http://translator.go.com/' ); - ShowTrad( 'Dictionary.com', - _("No known limits, powered by Systran"). - "
      ".sprintf(_("Number of supported language pairs: %s"),"24")." " , - 'http://www.dictionary.com/translate' ); - ShowTrad( 'Google Translate', - _("No known limits, powered by Systran"). - "
      ".sprintf(_("Number of supported language pairs: %s"),"12")." " , - 'http://www.google.com/translate' ); - ShowTrad( 'GPLTrans', - _("No known limits, powered by GPLTrans (free, open source)"). - "
      ".sprintf(_("Number of supported language pairs: %s"),"16")." " , - 'http://www.translator.cx/' ); - ShowTrad( 'InterTran', - _("No known limits, powered by Translation Experts' InterTran"). - "
      ".sprintf(_("Number of supported languages: %s"),"29")." " , - 'http://www.tranexp.com/' ); - ShowTrad( 'OTEnet', - _("Hellenic translations, no known limits, powered by Systran"). - "
      ".sprintf(_("Number of supported language pairs: %s"),"20")." " , - 'http://systran.otenet.gr/' ); - ShowTrad( 'PROMT', - _("Russian translations, maximum of 500 characters translated"). - "
      ".sprintf(_("Number of supported language pairs: %s"),"13")." " , - 'http://www.online-translator.com/' ); + translate_showtrad(); ?>

    @@ -156,34 +95,25 @@ function ShowTrad( $tit, $com, $url ) { _("Select your translator:") . '

    ' . + '
    - ' . _("Show translation box") . + '
    '. + ' - ' . _("Translate inside the SquirrelMail frames"). + "
    - ' . _("Show translation box") . - '
    '. - ' - ' . _("Translate inside the SquirrelMail frames"). - "
    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") . '
    '); - if (is_int($pos)) { - $new_body = substr($new_body, 0, $pos); - } - - $trans = get_html_translation_table(HTML_ENTITIES); - $trans[' '] = ' '; - $trans = array_flip($trans); - $new_body = strtr($new_body, $trans); - - $new_body = urldecode($new_body); - $new_body = strip_tags($new_body); - - /* I really don't like this next part ... */ - $new_body = str_replace('"', "''", $new_body); - $new_body = strtr($new_body, "\n", ' '); - - $function = 'translate_form_' . $translate_server; - $function($new_body); + include_once(SM_PATH . 'plugins/translate/functions.php'); + translate_read_form_function(); } /** - * Closes table tags in translation box - * @access private - */ -function translate_table_end() { - ?>
    -
    -
    - _("Translation Options"), - 'url' => '../plugins/translate/options.php', - 'desc' => _("Which translator should be used when you get messages in a different language?"), - 'js' => false - ); -} - -/** - * Gets user's translation preferences - * @access private - */ -function translate_pref() { - global $username, $data_dir; - global $translate_server, $translate_location; - global $translate_show_send, $translate_show_read; - global $translate_same_window; - - $translate_server = getPref($data_dir, $username, 'translate_server'); - if ($translate_server == '') { - $translate_server = 'babelfish'; - } - - $translate_location = getPref($data_dir, $username, 'translate_location'); - if ($translate_location == '') { - $translate_location = 'center'; - } - - $translate_show_send = getPref($data_dir, $username, 'translate_show_send'); - $translate_show_read = getPref($data_dir, $username, 'translate_show_read'); - $translate_same_window = getPref($data_dir, $username, 'translate_same_window'); -} - - -/** - * Tries to select default translation combination - * - * This function could be speed up. - * It basically negates the process if a ! is found in the beginning and - * matches a * at the end with 0 or more characters. - * - * @param string $test language code that has to be tested. - * @return boolean true if language code matches user's language. - * @access private - */ -function translate_does_it_match_language($test) { - global $squirrelmail_language; - $true = 1; - $false = 0; - $index = 0; - $smindex = 0; - - if (! $test || ! $squirrelmail_language) { - return $false; - } - - if ($test[$index] == '!') { - $index ++; - $true = 0; - $false = 1; - } - - if (($index == 0) && ($test == $squirrelmail_language)) { - return $true; - } - - while (isset($test[$index]) && $test[$index]) { - if ($test[$index] == '*') { - return $true; - } - if ($test[$index] != $squirrelmail_language[$smindex]) { - return $false; - } - $index ++; - $smindex ++; - } - - return $false; -} - -/** - * Creates language option selection box. - * - * @access private - */ -function translate_lang_opt($from, $to, $value, $text) { - global $translate_dir; - - $ret = '