0d22c64cf35a326951d34540a5575bcb6d8799ee
[squirrelmail.git] / plugins / translate / functions.php
1 <?php
2
3 /**
4 * SquirrelMail translate plugin functions
5 *
6 * @copyright &copy; 2004-2006 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package plugins
10 * @subpackage translate
11 */
12
13 /**
14 * do not allow to call this file directly
15 */
16 if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
17 (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
18 header("Location: ../../src/login.php");
19 die();
20 }
21 /** Load default config */
22 if (file_exists(SM_PATH . 'plugins/translate/config_default.php')) {
23 include_once(SM_PATH . 'plugins/translate/config_default.php');
24 } else {
25 /** Somebody removed default config */
26 global $translate_gpltrans_url;
27 $translate_gpltrans_url='';
28 global $disable_compose_translate;
29 $disable_compose_translate=true;
30 global $translate_default_engine;
31 $translate_default_engine='babelfish';
32 global $translate_babelfish_enabled;
33 $translate_babelfish_enabled=true;
34 global $translate_go_enabled;
35 $translate_go_enabled=false;
36 global $translate_dictionary_enabled;
37 $translate_dictionary_enabled=true;
38 global $translate_google_enabled;
39 $translate_google_enabled=true;
40 global $translate_intertran_enabled;
41 $translate_intertran_enabled=true;
42 global $translate_promt_enabled;
43 $translate_promt_enabled=true;
44 global $translate_otenet_enabled;
45 $translate_otenet_enabled=true;
46 global $translate_gpltrans_enabled;
47 $translate_gpltrans_enabled=true;
48 global $translate_custom_enabled;
49 $translate_custom_enabled=false;
50 // This is logged error message. Don't translate it.
51 error_log('SquirrelMail: default configuration file removed in translate plugin.');
52 }
53
54 /** Load site config */
55 if (file_exists(SM_PATH . 'config/translate_config.php')) {
56 include_once(SM_PATH . 'config/translate_config.php');
57 } elseif (file_exists(SM_PATH . 'plugins/translate/config.php')) {
58 include_once(SM_PATH . 'plugins/translate/config.php');
59 }
60
61 /** Setup functions */
62
63 /**
64 * Shows translation box in message display window
65 * @access private
66 */
67 function translate_read_form_function() {
68 global $color, $translate_server;
69 global $message, $translate_dir;
70 global $translate_show_read;
71 global $imapConnection, $wrap_at, $passed_id, $mailbox;
72 global $translate_gpltrans_url;
73
74 global $translate_babelfish_enabled, $translate_go_enabled,
75 $translate_dictionary_enabled, $translate_google_enabled,
76 $translate_gpltrans_enabled, $translate_intertran_enabled,
77 $translate_promt_enabled, $translate_otenet_enabled;
78 global $translate_custom_enabled;
79
80
81 if (!$translate_show_read) {
82 return;
83 }
84
85 $translate_server_option='translate_' . $translate_server . '_enabled';
86 if ($translate_server=='gpltrans' && $translate_gpltrans_url=='' ||
87 ! $$translate_server_option || ! function_exists('translate_form_' . $translate_server)) {
88 error_box(_("Selected translation engine is disabled. Please update your translation preferences."));
89 return;
90 }
91 $translate_dir = 'to';
92
93 $trans_ar = $message->findDisplayEntity(array(), array('text/plain'));
94 $body = '';
95 $final_body = '';
96 if ($trans_ar[0] != '') {
97 for ($i = 0; $i < count($trans_ar); $i++) {
98 /* reduced version of formatBody and translateText functions */
99
100 // get message entity information
101 $body_message = getEntity($message, $trans_ar[$i]);
102 // get message body
103 $body = mime_fetch_body ($imapConnection, $passed_id, $trans_ar[$i]);
104 // convert encoded messages
105 $body = decodeBody($body, $body_message->header->encoding);
106
107 /*
108 * if message part is html formated - convert spaces, html line feeds,
109 * less than and greater than html entities and remove tags
110 */
111 if ($body_message->header->type1 == 'html') {
112 $entity_conv = array('&nbsp;' => ' ',
113 '<p>' => "\n",
114 '<P>' => "\n",
115 '<br>' => "\n",
116 '<BR>' => "\n",
117 '<br />' => "\n",
118 '<BR />' => "\n",
119 '&gt;' => '>',
120 '&lt;' => '<');
121 $body = strtr($body, $entity_conv);
122 $body = strip_tags($body);
123 }
124 // remove whitespace
125 $body = trim($body);
126 // save processed text and parse other entity
127 $final_body.= charset_decode($body_message->header->getParameter('charset'),$body);
128 }
129
130 // add form if message is not empty
131 if (!empty($final_body)) {
132 $function = 'translate_form_' . $translate_server;
133 $function($final_body);
134 }
135 }
136 }
137
138 /**
139 * Adds translation option block
140 * @access private
141 */
142 function translate_optpage_function() {
143 global $optpage_blocks;
144 $optpage_blocks[] = array(
145 'name' => _("Translation Options"),
146 'url' => '../plugins/translate/options.php',
147 'desc' => _("Which translator should be used when you get messages in a different language?"),
148 'js' => false
149 );
150 }
151
152 /**
153 * Gets user's translation preferences
154 * @access private
155 */
156 function translate_pref_function() {
157 global $username, $data_dir;
158 global $translate_server, $translate_location;
159 global $translate_show_send, $translate_show_read;
160 global $translate_same_window,$translate_default_engine;
161
162 $translate_server = getPref($data_dir, $username, 'translate_server',$translate_default_engine);
163
164 $translate_location = getPref($data_dir, $username, 'translate_location','center');
165
166 $translate_show_send = getPref($data_dir, $username, 'translate_show_send');
167 $translate_show_read = getPref($data_dir, $username, 'translate_show_read');
168 $translate_same_window = getPref($data_dir, $username, 'translate_same_window');
169 }
170
171 /**
172 * Should add translation options in compose window
173 *
174 * Unimplemented
175 * @access private
176 */
177 function translate_button_function() {
178 global $translate_show_send;
179
180 if (! $translate_show_send) {
181 return;
182 }
183 }
184
185 /**
186 * Save translation options
187 */
188 function translate_save_function() {
189 global $username, $data_dir;
190 // Save preferences
191 if (sqgetGlobalVar('submit_translate',$tmp,SQ_POST)) {
192 if (sqgetGlobalVar('translate_translate_server',$translate_server,SQ_POST)) {
193 setPref($data_dir, $username, 'translate_server', $translate_server);
194 } else {
195 setPref($data_dir, $username, 'translate_server', $translate_default_engine);
196 }
197
198 if (sqgetGlobalVar('translate_translate_location',$translate_location,SQ_POST)) {
199 setPref($data_dir, $username, 'translate_location', $translate_location);
200 } else {
201 setPref($data_dir, $username, 'translate_location', 'center');
202 }
203
204 if (sqgetGlobalVar('translate_translate_show_read',$translate_show_read,SQ_POST)) {
205 setPref($data_dir, $username, 'translate_show_read', '1');
206 } else {
207 setPref($data_dir, $username, 'translate_show_read', '');
208 }
209
210 if (sqgetGlobalVar('translate_translate_show_send',$translate_show_send,SQ_POST)) {
211 setPref($data_dir, $username, 'translate_show_send', '1');
212 } else {
213 setPref($data_dir, $username, 'translate_show_send', '');
214 }
215
216 if (sqgetGlobalVar('translate_translate_same_window',$translate_same_windows,SQ_POST)) {
217 setPref($data_dir, $username, 'translate_same_window', '1');
218 } else {
219 setPref($data_dir, $username, 'translate_same_window', '');
220 }
221 }
222 }
223
224 /**
225 * Set option page name
226 * @access private
227 */
228 function translate_set_loadinfo_function() {
229 global $optpage, $optpage_name;
230 if ($optpage=='translate') {
231 $optpage_name=_("Translation Preferences");
232 }
233 }
234
235 /** Option functions */
236
237 /**
238 * Creates server selection options
239 * @access private
240 */
241 function translate_showoption() {
242 global $translate_babelfish_enabled, $translate_go_enabled,
243 $translate_dictionary_enabled, $translate_google_enabled,
244 $translate_gpltrans_enabled, $translate_intertran_enabled,
245 $translate_promt_enabled, $translate_otenet_enabled;
246 global $translate_custom_enabled, $translate_gpltrans_url;
247
248 if ($translate_babelfish_enabled) translate_showoption_internal('server','babelfish', 'Babelfish');
249 if ($translate_go_enabled) translate_showoption_internal('server','go', 'Go.com');
250 if ($translate_dictionary_enabled) translate_showoption_internal('server','dictionary', 'Dictionary.com');
251 if ($translate_google_enabled) translate_showoption_internal('server','google', 'Google Translate');
252 if ($translate_gpltrans_enabled && $translate_gpltrans_url!='')
253 translate_showoption_internal('server','gpltrans', 'GPLTrans');
254 if ($translate_intertran_enabled) translate_showoption_internal('server','intertran', 'Intertran');
255 if ($translate_otenet_enabled) translate_showoption_internal('server','otenet', 'OTEnet');
256 if ($translate_promt_enabled) translate_showoption_internal('server','promt', 'PROMT');
257 if ($translate_custom_enabled && function_exists('translate_custom_showoption')) {
258 translate_custom_showoption();
259 }
260 }
261
262 /**
263 * Displays comments about available translation engines
264 * @access private
265 */
266 function translate_showtrad() {
267 global $translate_babelfish_enabled, $translate_go_enabled,
268 $translate_dictionary_enabled, $translate_google_enabled,
269 $translate_gpltrans_enabled, $translate_intertran_enabled,
270 $translate_promt_enabled, $translate_otenet_enabled;
271 global $translate_gpltrans_url, $translate_custom_enabled;
272
273 if ($translate_babelfish_enabled) translate_showtrad_internal( 'Babelfish',
274 _("Maximum of 150 words translated, powered by Systran").
275 '<br />'.sprintf(_("Number of supported language pairs: %s"),'36').' ' ,
276 'http://babelfish.altavista.com/' );
277 if ($translate_go_enabled) translate_showtrad_internal( 'Translator.Go.com',
278 _("Maximum of 25 kilobytes translated, powered by Systran").
279 '<br />'.sprintf(_("Number of supported language pairs: %s"),'10').' ' ,
280 'http://translator.go.com/' );
281 if ($translate_dictionary_enabled) translate_showtrad_internal( 'Dictionary.com',
282 _("No known limits, powered by Systran").
283 '<br />'.sprintf(_("Number of supported language pairs: %s"),'24').' ' ,
284 'http://www.dictionary.com/translate' );
285 if ($translate_google_enabled) translate_showtrad_internal( 'Google Translate',
286 _("No known limits, powered by Systran").
287 '<br />'.sprintf(_("Number of supported language pairs: %s"),'20').' ' ,
288 'http://www.google.com/translate' );
289 if ($translate_gpltrans_enabled && $translate_gpltrans_url!='') translate_showtrad_internal( 'GPLTrans',
290 _("No known limits, powered by GPLTrans (free, open source)").
291 '<br />'.sprintf(_("Number of supported language pairs: %s"),'16').' ' ,
292 'http://www.translator.cx/' );
293 if ($translate_intertran_enabled) translate_showtrad_internal( 'InterTran',
294 _("No known limits, powered by Translation Experts' InterTran").
295 '<br />'.sprintf(_("Number of supported languages: %s"),'29').' ' ,
296 'http://www.tranexp.com/' );
297 if ($translate_otenet_enabled) translate_showtrad_internal( 'OTEnet',
298 _("Hellenic translations, no known limits, powered by Systran").
299 '<br />'.sprintf(_("Number of supported language pairs: %s"),'20').' ' ,
300 'http://systran.otenet.gr/' );
301 if ($translate_promt_enabled) translate_showtrad_internal( 'PROMT',
302 _("Russian translations, maximum of 500 characters translated").
303 '<br />'.sprintf(_("Number of supported language pairs: %s"),'16').' ' ,
304 'http://www.online-translator.com/' );
305
306 if ($translate_custom_enabled && function_exists('translate_custom_showtrad')) {
307 translate_custom_showtrad();
308 }
309 }
310
311 /**
312 * Creates options for translation selection boxes
313 * @param string $Var option type (server,location)
314 * @param string $value option value
315 * @param string $Desc description of translation server
316 * @access private
317 * @since 1.5.1
318 */
319 function translate_showoption_internal($Var,$value, $Desc) {
320 $Var='translate_' . $Var;
321
322 global $$Var;
323
324 echo '<option value="' . $value . '"';
325 if ($$Var == $value) {
326 echo ' selected="selected"';
327 }
328 echo '>' . $Desc . "</option>\n";
329 }
330
331 /**
332 * Creates translation server description
333 * @param string $tit title
334 * @param string $com comments about translation server
335 * @param string $url url of translation server
336 * @access private
337 */
338 function translate_showtrad_internal( $tit, $com, $url ) {
339 echo "<li><b>$tit</b> - ".
340 $com .
341 "[ <a href=\"$url\" target=\"_blank\">$tit</a> ]</li>";
342 }
343
344 /** Internal functions */
345
346 /**
347 * Closes table tags in translation box
348 * @access private
349 */
350 function translate_table_end() {
351 ?></td>
352 </tr>
353 </table>
354 </td>
355 </tr>
356 </table>
357 </form>
358 <?php
359 }
360
361 /**
362 * Tries to select default translation combination
363 *
364 * This function could be speed up.
365 * It basically negates the process if a ! is found in the beginning and
366 * matches a * at the end with 0 or more characters.
367 *
368 * @param string $test language code that has to be tested.
369 * @return boolean true if language code matches user's language.
370 * @access private
371 */
372 function translate_does_it_match_language($test) {
373 global $squirrelmail_language;
374 $true = 1;
375 $false = 0;
376 $index = 0;
377 $smindex = 0;
378
379 if (! $test || ! $squirrelmail_language) {
380 return $false;
381 }
382
383 if ($test[$index] == '!') {
384 $index ++;
385 $true = 0;
386 $false = 1;
387 }
388
389 if (($index == 0) && ($test == $squirrelmail_language)) {
390 return $true;
391 }
392
393 while (isset($test[$index]) && $test[$index]) {
394 if ($test[$index] == '*') {
395 return $true;
396 }
397 if ($test[$index] != $squirrelmail_language[$smindex]) {
398 return $false;
399 }
400 $index ++;
401 $smindex ++;
402 }
403
404 return $false;
405 }
406
407 /**
408 * Creates language option selection box.
409 * @param string $from
410 * @param string $to
411 * @param string $value
412 * @param string $text
413 * @access private
414 */
415 function translate_lang_opt($from, $to, $value, $text) {
416 global $translate_dir;
417
418 $ret = ' <option value="' . $value . '"';
419
420 if (translate_does_it_match_language($to) && ($translate_dir == 'to')) {
421 $ret .= ' selected="selected"';
422 }
423
424 if (translate_does_it_match_language($from) && ($translate_dir == 'from')) {
425 $ret .= ' selected="selected"';
426 }
427
428 $ret .= '>' . $text . "</option>\n";
429
430 return( $ret );
431 }
432
433 /**
434 * Starts translation box
435 *
436 * @param string $action url that has to recieve message for translation
437 * @param string $charset (since sm 1.5.1) character set, that should be used
438 * to submit 8bit information.
439 * @access private
440 */
441 function translate_new_form($action,$charset=null) {
442 global $translate_dir, $translate_location;
443 global $color, $translate_same_window;
444
445 echo '<form action="';
446
447 if ($translate_dir == 'to') {
448 echo $action;
449 } else {
450 echo 'translate.php';
451 }
452
453 echo '" method="post"';
454
455 if (!$translate_same_window) {
456 echo ' target="_blank"';
457 }
458
459 if (! is_null($charset))
460 echo ' accept-charset="'.htmlspecialchars($charset).'"';
461
462 echo ">\n";
463
464 ?><table align="<?php echo $translate_location; ?>" cellpadding="3" cellspacing="0" border="0" bgcolor="<?php echo $color[10]; ?>">
465 <tr>
466 <td>
467 <table cellpadding="2" cellspacing="1" border="0" bgcolor="<?php echo $color[5]; ?>">
468 <tr>
469 <td><?php
470 }
471
472 /**
473 * Babelfish translation engine functions
474 *
475 * @param string $message text that has to be translated.
476 * @access private
477 */
478 function translate_form_babelfish($message) {
479 translate_new_form('http://babelfish.altavista.com/babelfish/tr','utf-8');
480 ?>
481 <input type="hidden" name="doit" value="done" />
482 <input type="hidden" name="intl" value="1" />
483 <input type="hidden" name="tt" value="urltext" />
484 <input type="hidden" name="trtext" value="<?php echo $message; ?>" />
485 <select name="lp"><?php
486 echo translate_lang_opt('zh_CN', '', 'zh_en',
487 sprintf( _("%s to %s"),_("Chinese, Simplified"),_("English"))) .
488 translate_lang_opt('zh_TW', '', 'zt_en',
489 sprintf( _("%s to %s"),_("Chinese, Traditional"),_("English"))) .
490 translate_lang_opt('en_US', 'zh_CN', 'en_zh',
491 sprintf( _("%s to %s"),_("English"),_("Chinese, Simplified"))) .
492 translate_lang_opt('en_US', 'zh_TW', 'en_zt',
493 sprintf( _("%s to %s"),_("English"),_("Chinese, Traditional"))) .
494 translate_lang_opt('en_US', 'nl_NL', 'en_nl',
495 sprintf( _("%s to %s"),_("English"),_("Dutch"))) .
496 translate_lang_opt('en_US', 'fr_FR', 'en_fr',
497 sprintf( _("%s to %s"),_("English"),_("French"))) .
498 translate_lang_opt('en_US', 'de_DE', 'en_de',
499 sprintf( _("%s to %s"),_("English"),_("German"))) .
500 translate_lang_opt('en_US', 'el_GR', 'en_el',
501 sprintf( _("%s to %s"),_("English"),_("Greek"))) .
502 translate_lang_opt('en_US', 'it_IT', 'en_it',
503 sprintf( _("%s to %s"),_("English"),_("Italian"))) .
504 translate_lang_opt('en_US', 'ja_JP', 'en_ja',
505 sprintf( _("%s to %s"),_("English"),_("Japanese"))) .
506 translate_lang_opt('en_US', 'ko_KR', 'en_ko',
507 sprintf( _("%s to %s"),_("English"),_("Korean"))) .
508 translate_lang_opt('en_US', 'pt*', 'en_pt',
509 sprintf( _("%s to %s"),_("English"),_("Portuguese"))) .
510 translate_lang_opt('en_US', 'ru_RU', 'en_ru',
511 sprintf( _("%s to %s"),_("English"),_("Russian"))) .
512 translate_lang_opt('en_US', 'es_ES', 'en_es',
513 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
514 translate_lang_opt('nl_NL', '', 'nl_en',
515 sprintf( _("%s to %s"),_("Dutch"),_("English"))) .
516 translate_lang_opt('nl_NL', '', 'nl_fr',
517 sprintf( _("%s to %s"),_("Dutch"),_("French"))) .
518 translate_lang_opt('fr_FR', '', 'fr_en',
519 sprintf( _("%s to %s"),_("French"),_("English"))) .
520 translate_lang_opt('fr_FR', '', 'fr_de',
521 sprintf( _("%s to %s"),_("French"),_("German"))) .
522 translate_lang_opt('fr_FR', '', 'fr_el',
523 sprintf( _("%s to %s"),_("French"),_("Greek"))) .
524 translate_lang_opt('fr_FR', '', 'fr_it',
525 sprintf( _("%s to %s"),_("French"),_("Italian"))) .
526 translate_lang_opt('fr_FR', '', 'fr_pt',
527 sprintf( _("%s to %s"),_("French"),_("Portuguese"))) .
528 translate_lang_opt('fr_FR', '', 'fr_nl',
529 sprintf( _("%s to %s"),_("French"),_("Dutch"))) .
530 translate_lang_opt('fr_FR', '', 'fr_es',
531 sprintf( _("%s to %s"),_("French"),_("Spanish"))) .
532 translate_lang_opt('de_DE', 'en_US', 'de_en',
533 sprintf( _("%s to %s"),_("German"),_("English"))) .
534 translate_lang_opt('de_DE', '', 'de_fr',
535 sprintf( _("%s to %s"),_("German"),_("French"))) .
536 translate_lang_opt('el_GR', '', 'el_en',
537 sprintf( _("%s to %s"),_("Greek"),_("English"))) .
538 translate_lang_opt('el_GR', '', 'el_fr',
539 sprintf( _("%s to %s"),_("Greek"),_("French"))) .
540 translate_lang_opt('it_IT', '', 'it_en',
541 sprintf( _("%s to %s"),_("Italian"),_("English"))) .
542 translate_lang_opt('it_IT', '', 'it_fr',
543 sprintf( _("%s to %s"),_("Italian"),_("French"))) .
544 translate_lang_opt('ja_JP', '', 'ja_en',
545 sprintf( _("%s to %s"),_("Japanese"),_("English"))) .
546 translate_lang_opt('ko_KR', '', 'ko_en',
547 sprintf( _("%s to %s"),_("Korean"),_("English"))) .
548 translate_lang_opt('pt*', '', 'pt_en',
549 sprintf( _("%s to %s"),_("Portuguese"),_("English"))) .
550 translate_lang_opt('pt*', '', 'pt_fr',
551 sprintf( _("%s to %s"),_("Portuguese"),_("French"))) .
552 translate_lang_opt('ru_RU', '', 'ru_en',
553 sprintf( _("%s to %s"),_("Russian"),_("English"))) .
554 translate_lang_opt('es_ES', '', 'es_en',
555 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
556 translate_lang_opt('es_ES', '', 'es_fr',
557 sprintf( _("%s to %s"),_("Spanish"),_("French")));
558 echo '</select>'.
559 'Babelfish: <input type="submit" value="' . _("Translate") . '" />';
560
561 translate_table_end();
562 }
563
564 /**
565 * go.com translation engine (disabled)
566 *
567 * @param string $message text that has to be translated
568 * @access private
569 */
570 function translate_form_go($message) {
571 translate_new_form('http://translator.go.com/cb/trans_entry');
572 ?>
573 <input type="hidden" name="input_type" value="text" />
574 <select name="lp"><?php
575 echo translate_lang_opt('en_US', 'es_ES', 'en_sp',
576 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
577 translate_lang_opt('en_US', 'fr_FR', 'en_fr',
578 sprintf( _("%s to %s"),_("English"),_("French"))) .
579 translate_lang_opt('en_US', 'de_DE', 'en_ge',
580 sprintf( _("%s to %s"),_("English"),_("German"))) .
581 translate_lang_opt('en_US', 'it_IT', 'en_it',
582 sprintf( _("%s to %s"),_("English"),_("Italian"))) .
583 translate_lang_opt('en_US', 'pt*', 'en_pt',
584 sprintf( _("%s to %s"),_("English"),_("Portuguese"))) .
585 translate_lang_opt('es_ES', '', 'sp_en',
586 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
587 translate_lang_opt('fr_FR', '', 'fr_en',
588 sprintf( _("%s to %s"),_("French"),_("English"))) .
589 translate_lang_opt('de_DE', 'en_US', 'ge_en',
590 sprintf( _("%s to %s"),_("German"),_("English"))) .
591 translate_lang_opt('it_IT', '', 'it_en',
592 sprintf( _("%s to %s"),_("Italian"),_("English"))) .
593 translate_lang_opt('pt*', '', 'pt_en',
594 sprintf( _("%s to %s"),_("Portuguese"),_("English")));
595 echo '</select>'.
596 '<input type="hidden" name="text" value="'.$message.'" />'.
597 'Go.com: <input type="submit" value="' . _("Translate") . '" />';
598
599 translate_table_end();
600 }
601
602 /**
603 * intertran translation engine
604 *
605 * @param string $message text that has to be translated
606 * @access private
607 */
608 function translate_form_intertran($message) {
609 translate_new_form('http://intertran.tranexp.com/Translate/result.shtml');
610 echo '<input type="hidden" name="topframe" value="yes" />'.
611 '<input type="hidden" name="type" value="text" />'.
612 '<input type="hidden" name="keyb" value="non" />'.
613 '<input type="hidden" name="text" value="'.$message.'" />';
614
615 $left = '<select name="from">' .
616 translate_lang_opt('pt_BR', '', 'pob', _("Brazilian Portuguese")).
617 translate_lang_opt('bg_BG', '', 'bul', _("Bulgarian") . ' (CP 1251)').
618 translate_lang_opt('hr_HR', '', 'cro', _("Croatian") . ' (CP 1250)').
619 translate_lang_opt('cs_CZ', '', 'che', _("Czech") . ' (CP 1250)').
620 translate_lang_opt('da_DK', '', 'dan', _("Danish")).
621 translate_lang_opt('nl_NL', '', 'dut', _("Dutch")).
622 translate_lang_opt('en_US', '!en', 'eng', _("English")).
623 translate_lang_opt('tl_PH', '', 'tag', _("Filipino (Tagalog)")).
624 translate_lang_opt('fi_FI', '', 'fin', _("Finnish")).
625 translate_lang_opt('fr_FR', '', 'fre', _("French")).
626 translate_lang_opt('de_DE', '', 'ger', _("German")).
627 translate_lang_opt('el_GR', '', 'grk', _("Greek")).
628 translate_lang_opt('hu_HU', '', 'hun', _("Hungarian") . ' (CP 1250)').
629 translate_lang_opt('is_IS', '', 'ice', _("Icelandic")).
630 translate_lang_opt('it_IT', '', 'ita', _("Italian")).
631 translate_lang_opt('ja_JP', '', 'jpn', _("Japanese") . ' (Shift JIS)').
632 translate_lang_opt('la', '', 'ltt', _("Latin")).
633 translate_lang_opt('es*', '', 'spl', _("Latin American Spanish")).
634 translate_lang_opt('no*', '', 'nor', _("Norwegian")).
635 translate_lang_opt('pl_PL', '', 'pol', _("Polish") . ' (ISO 8859-2)').
636 translate_lang_opt('pt*', '', 'poe', _("Portuguese")).
637 translate_lang_opt('ro_RO', '', 'rom', _("Romanian") . ' (CP 1250)').
638 translate_lang_opt('ru_RU', '', 'rus', _("Russian") . ' (CP 1251)').
639 translate_lang_opt('sr_YU', '', 'sel', _("Serbian") . ' (CP 1250)').
640 translate_lang_opt('sl_SI', '', 'slo', _("Slovenian") . ' (CP 1250)').
641 translate_lang_opt('es_ES', '', 'spa', _("Spanish")).
642 translate_lang_opt('sv_SE', '', 'swe', _("Swedish")).
643 translate_lang_opt('tr_TR', '', 'tur', _("Turkish") . ' (CP 1254)').
644 translate_lang_opt('cy_GB', '', 'wel', _("Welsh")).
645 '</select>';
646
647 $right = '<select name="to">'.
648 translate_lang_opt('', 'pt_BR', 'pob', _("Brazilian Portuguese")).
649 translate_lang_opt('', 'bg_BG', 'bul', _("Bulgarian") . ' (CP 1251)').
650 translate_lang_opt('', 'hr_HR', 'cro', _("Croatian") . ' (CP 1250)').
651 translate_lang_opt('', 'cs_CZ', 'che', _("Czech") . ' (CP 1250)').
652 translate_lang_opt('', 'da_DK', 'dan', _("Danish")).
653 translate_lang_opt('', 'nl_NL', 'dut', _("Dutch")).
654 translate_lang_opt('!en', 'en_US', 'eng', _("English")).
655 translate_lang_opt('', 'tl_PH', 'tag', _("Filipino (Tagalog)")).
656 translate_lang_opt('', 'fi_FI', 'fin', _("Finnish")).
657 translate_lang_opt('', 'fr_FR', 'fre', _("French")).
658 translate_lang_opt('', 'de_DE', 'ger', _("German")).
659 translate_lang_opt('', 'el_GR', 'grk', _("Greek")).
660 translate_lang_opt('', 'hu_HU', 'hun', _("Hungarian") . ' (CP 1250)').
661 translate_lang_opt('', 'is_IS', 'ice', _("Icelandic")).
662 translate_lang_opt('', 'it_IT', 'ita', _("Italian")).
663 translate_lang_opt('', 'ja_JP', 'jpn', _("Japanese") . ' (Shift JIS)').
664 translate_lang_opt('', 'la', 'ltt', _("Latin")).
665 translate_lang_opt('', 'es*', 'spl', _("Latin American Spanish")).
666 translate_lang_opt('', 'no*', 'nor', _("Norwegian")).
667 translate_lang_opt('', 'pl_PL', 'pol', _("Polish") . ' (ISO 8859-2)').
668 translate_lang_opt('', 'pt_PT', 'poe', _("Portuguese")).
669 translate_lang_opt('', 'ro_RO', 'rom', _("Romanian") . ' (CP 1250)').
670 translate_lang_opt('', 'ru_RU', 'rus', _("Russian") . ' (CP 1251)').
671 translate_lang_opt('', 'sr_YU', 'sel', _("Serbian") . ' (CP 1250)').
672 translate_lang_opt('', 'sl_SI', 'slo', _("Slovenian") . ' (CP 1250)').
673 translate_lang_opt('', 'es_ES', 'spa', _("Spanish")).
674 translate_lang_opt('', 'sv_SE', 'swe', _("Swedish")).
675 translate_lang_opt('', 'tr_TR', 'tur', _("Turkish") . ' (CP 1254)').
676 translate_lang_opt('', 'cy_GB', 'wel', _("Welsh")).
677 '</select>';
678 printf( _("%s to %s"), $left, $right );
679 echo 'InterTran: <input type="submit" value="' . _("Translate") . '" />';
680
681 translate_table_end();
682 }
683
684 /**
685 * gpltrans translation engine
686 *
687 * @param string $message text that has to be translated
688 * @access private
689 */
690 function translate_form_gpltrans($message) {
691 global $translate_gpltrans_url;
692
693 // make sure that it is not empty
694 if ($translate_gpltrans_url=='')
695 $translate_gpltrans_url='http://www.translator.cx/cgi-bin/gplTrans';
696
697 translate_new_form($translate_gpltrans_url);
698 echo '<select name="language">'.
699 translate_lang_opt('', 'nl_NL', 'dutch_dict', _("Dutch")).
700 translate_lang_opt('', 'fr_FR', 'french_dict', _("French")).
701 translate_lang_opt('', 'de_DE', 'german_dict', _("German")).
702 translate_lang_opt('', 'id_ID', 'indonesian_dict', _("Indonesian")).
703 translate_lang_opt('', 'it_IT', 'italian_dict', _("Italian")).
704 translate_lang_opt('', 'la', 'latin_dict', _("Latin")).
705 translate_lang_opt('', 'pt*', 'portuguese_dict', _("Portuguese")).
706 translate_lang_opt('', 'es_ES', 'spanish_dict', _("Spanish")).
707 '</select>';
708 echo '<select name="toenglish">';
709 echo '<option value="yes">'. _("to English") . '</option>';
710 echo '<option value="no" selected="selected">' . _("from English") . '</option></select>';
711 echo '<input type="hidden" name="text" value="'.$message.'" />'.
712 'GPLTrans: <input type="submit" value="' . _("Translate") . '" />';
713
714 translate_table_end();
715 }
716
717 /**
718 * reference.com (dictionary) translation engine
719 *
720 * @param string $message text that has to be translated
721 * @access private
722 */
723 function translate_form_dictionary($message) {
724 translate_new_form('http://dictionary.reference.com/translate/text.html');
725 list($usec, $sec) = explode(' ',microtime());
726 $time = $sec . (float)$usec*100000000;
727 echo '<input type="hidden" name="text" value="'.$message.'" />'.
728 '<input type="hidden" name="ts" value="'.$time.'" />'.
729 '<select name="lp">'.
730 translate_lang_opt('en_US', 'zh_CN', 'en_zh',
731 sprintf( _("%s to %s"),_("English"),_("Chinese, Simplified"))) .
732 translate_lang_opt('en_US', 'zh_TW', 'en_zt',
733 sprintf( _("%s to %s"),_("English"),_("Chinese, Traditional"))) .
734 translate_lang_opt('en_US', 'nl_NL', 'en_nl',
735 sprintf( _("%s to %s"),_("English"),_("Dutch"))) .
736 translate_lang_opt('en_US', 'fr_FR', 'en_fr',
737 sprintf( _("%s to %s"),_("English"),_("French"))) .
738 translate_lang_opt('en_US', 'de_DE', 'en_ge',
739 sprintf( _("%s to %s"),_("English"),_("German"))) .
740 translate_lang_opt('en_US', 'el_GR', 'en_el',
741 sprintf( _("%s to %s"),_("English"),_("Greek"))) .
742 translate_lang_opt('en_US', 'it_IT', 'en_it',
743 sprintf( _("%s to %s"),_("English"),_("Italian"))) .
744 translate_lang_opt('en_US', 'ja_JP', 'en_ja',
745 sprintf( _("%s to %s"),_("English"),_("Japanese"))) .
746 translate_lang_opt('en_US', 'ko_KR', 'en_ko',
747 sprintf( _("%s to %s"),_("English"),_("Korean"))) .
748 translate_lang_opt('en_US', 'pt*', 'en_pt',
749 sprintf( _("%s to %s"),_("English"),_("Portuguese"))) .
750 translate_lang_opt('en_US', 'ru_RU', 'en_ru',
751 sprintf( _("%s to %s"),_("English"),_("Russian"))) .
752 translate_lang_opt('en_US', 'es_ES', 'en_es',
753 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
754 translate_lang_opt('zh_CN', '', 'zh_en',
755 sprintf( _("%s to %s"),_("Chinese, Simplified"),_("English"))) .
756 translate_lang_opt('zh_TW', '', 'zt_en',
757 sprintf( _("%s to %s"),_("Chinese, Traditional"),_("English"))) .
758 translate_lang_opt('nl_NL', '', 'nl_en',
759 sprintf( _("%s to %s"),_("Dutch"),_("English"))) .
760 translate_lang_opt('fr_FR', '', 'fr_en',
761 sprintf( _("%s to %s"),_("French"),_("English"))) .
762 translate_lang_opt('de_DE', 'en_US', 'ge_en',
763 sprintf( _("%s to %s"),_("German"),_("English"))) .
764 translate_lang_opt('el_GR', '', 'el_en',
765 sprintf( _("%s to %s"),_("Greek"),_("English"))) .
766 translate_lang_opt('it_IT', '', 'it_en',
767 sprintf( _("%s to %s"),_("Italian"),_("English"))) .
768 translate_lang_opt('ja_JP', '', 'ja_en',
769 sprintf( _("%s to %s"),_("Japanese"),_("English"))) .
770 translate_lang_opt('ko_KR', '', 'ko_en',
771 sprintf( _("%s to %s"),_("Korean"),_("English"))) .
772 translate_lang_opt('pt*', '', 'pt_en',
773 sprintf( _("%s to %s"),_("Portuguese"),_("English"))) .
774 translate_lang_opt('ru_RU', '', 'ru_en',
775 sprintf( _("%s to %s"),_("Russian"),_("English"))) .
776 translate_lang_opt('es_ES', '', 'es_en',
777 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
778 '</select>'.
779 'Dictionary.com: <input type="submit" value="'._("Translate").'" />';
780
781 translate_table_end();
782 }
783
784 /**
785 * otenet translation engine
786 *
787 * @param string $message text that has to be translated
788 * @access private
789 */
790 function translate_form_otenet($message) {
791 translate_new_form('http://trans.otenet.gr/systran/box','windows-1253');
792 ?>
793 <input type="hidden" name="doit" value="done" />
794 <input type="hidden" name="partner" value="OTEnet-en" />
795 <input type="hidden" name="urltext" value="<?php echo $message; ?>" />
796 <select name="lp" size="1"><?php
797 echo translate_lang_opt('en_US', 'el_GR', 'en_el',
798 sprintf( _("%s to %s"),_("English"),_("Greek"))) .
799 translate_lang_opt('el_GR', 'en_US', 'el_en',
800 sprintf( _("%s to %s"),_("Greek"),_("English"))) .
801 translate_lang_opt('fr_FR', '', 'fr_el',
802 sprintf( _("%s to %s"),_("French"),_("Greek"))) .
803 translate_lang_opt('el_GR', 'fr_FR', 'el_fr',
804 sprintf( _("%s to %s"),_("Greek"),_("French"))) .
805 translate_lang_opt('#', '', '', '----------------') .
806 translate_lang_opt('en_US', '', 'en_fr',
807 sprintf( _("%s to %s"),_("English"),_("French"))) .
808 translate_lang_opt('fr_FR', '', 'fr_en',
809 sprintf( _("%s to %s"),_("French"),_("English"))) .
810 translate_lang_opt('en_US', 'de_DE', 'en_de',
811 sprintf( _("%s to %s"),_("English"),_("German"))) .
812 translate_lang_opt('de_DE', '', 'de_en',
813 sprintf( _("%s to %s"),_("German"),_("English"))) .
814 translate_lang_opt('en_US', 'es_ES', 'en_es',
815 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
816 translate_lang_opt('es_ES', '', 'es_en',
817 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
818 translate_lang_opt('en_US', 'it_IT', 'en_it',
819 sprintf( _("%s to %s"),_("English"),_("Italian"))) .
820 translate_lang_opt('it_IT', '', 'it_en',
821 sprintf( _("%s to %s"),_("Italian"),_("English"))) .
822 translate_lang_opt('en_US', 'pt*', 'en_pt',
823 sprintf( _("%s to %s"),_("English"),_("Portuguese"))) .
824 translate_lang_opt('pt*', '', 'pt_en',
825 sprintf( _("%s to %s"),_("Portuguese"),_("English"))) .
826 translate_lang_opt('fr_FR', '', 'fr_de',
827 sprintf( _("%s to %s"),_("French"),_("German"))) .
828 translate_lang_opt('de_DE', '', 'de_fr',
829 sprintf( _("%s to %s"),_("German"),_("French"))) .
830 translate_lang_opt('fr_FR', '', 'fr_es',
831 sprintf( _("%s to %s"),_("French"),_("Spanish"))) .
832 translate_lang_opt('es_ES', '', 'es_fr',
833 sprintf( _("%s to %s"),_("Spanish"),_("French"))) .
834 translate_lang_opt('fr_FR', 'nl_NL', 'fr_nl',
835 sprintf( _("%s to %s"),_("French"),_("Dutch"))) .
836 translate_lang_opt('nl_NL', '', 'nl_fr',
837 sprintf( _("%s to %s"),_("Dutch"),_("French"))) ;
838 echo '</select>'.
839 'OTEnet: <input type="submit" value="' . _("Translate") . '" />';
840
841 translate_table_end();
842 }
843
844 /**
845 * promt translation engine
846 *
847 * @param string $message text that has to be translated
848 * @access private
849 */
850 function translate_form_promt($message) {
851 translate_new_form('http://www.online-translator.com/text.asp#tr_form','windows-1251');
852 echo '<input type="hidden" name="status" value="translate" />';
853 echo '<input type="hidden" name="source" value="'.$message.'" />';
854 echo _("Interface language")." : ";
855 echo "<select size=\"1\" name=\"lang\">\n";
856 echo '<option value="en">' . _("English") . "</option>\n";
857 echo '<option value="ru">' . _("Russian") . "</option>\n";
858 echo '<option value="de">' . _("German") . "</option>\n";
859 echo '<option value="fr">' . _("French") . "</option>\n";
860 echo '<option value="es">' . _("Spanish") . "</option>\n";
861 echo "</select><br />\n";
862 echo _("Translation direction")." : ";
863 echo '<select size="1" id="direction" name="direction">';
864 echo translate_lang_opt('en_US', 'ru_RU', 'er',
865 sprintf( _("%s to %s"),_("English"),_("Russian"))) .
866 translate_lang_opt('ru_RU', 'en_US', 're',
867 sprintf( _("%s to %s"),_("Russian"),_("English"))) .
868 translate_lang_opt('de_DE', '', 'gr',
869 sprintf( _("%s to %s"),_("German"),_("Russian"))) .
870 translate_lang_opt('ru_RU', 'de_DE', 'rg',
871 sprintf( _("%s to %s"),_("Russian"),_("German"))) .
872 translate_lang_opt('fr_FR', '', 'fr',
873 sprintf( _("%s to %s"),_("French"),_("Russian"))) .
874 translate_lang_opt('ru_RU', 'fr_FR', 'rf',
875 sprintf( _("%s to %s"),_("Russian"),_("French"))) .
876 translate_lang_opt('es_ES', '', 'sr',
877 sprintf( _("%s to %s"),_("Spanish"),_("Russian"))) .
878 translate_lang_opt('ru_RU', 'es_ES', 'rs',
879 sprintf( _("%s to %s"),_("Russian"),_("Spanish"))) .
880 translate_lang_opt('it_IT', '', 'ir',
881 sprintf( _("%s to %s"),_("Italian"),_("Russian"))) .
882 translate_lang_opt('en_US', '', 'eg',
883 sprintf( _("%s to %s"),_("English"),_("German"))) .
884 translate_lang_opt('de_DE', '', 'ge',
885 sprintf( _("%s to %s"),_("German"),_("English"))) .
886 translate_lang_opt('en_US', '', 'es',
887 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
888 translate_lang_opt('es_ES', '', 'se',
889 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
890 translate_lang_opt('en_US', '', 'ef',
891 sprintf( _("%s to %s"),_("English"),_("French"))) .
892 translate_lang_opt('fr_FR', '', 'fe',
893 sprintf( _("%s to %s"),_("French"),_("English"))) .
894 translate_lang_opt('en_US', '', 'ep',
895 sprintf( _("%s to %s"),_("English"),_("Portuguese")));
896 echo "</select><br />\n";
897 echo "<input type=\"hidden\" name=\"template\" value=\"General\" />\n";
898 echo _("Transliterate unknown words:") . '<input type="checkbox" id="transliterate" name="transliterate" /><br />';
899 echo 'PROMT: <input type="submit" value="' . _("Translate") . '" />';
900
901 translate_table_end();
902 }
903
904 /**
905 * google translation engine
906 *
907 * @param string $message text that has to be translated
908 * @access private
909 */
910 function translate_form_google($message) {
911 translate_new_form('http://www.google.com/translate_t','utf-8');
912 echo '<input type="hidden" name="text" value="' . $message . '" />';
913 echo '<select name="langpair">'.
914 translate_lang_opt('en_US', 'de_DE', 'en|de',
915 sprintf( _("%s to %s"),_("English"),_("German"))) .
916 translate_lang_opt('en_US', 'es_ES', 'en|es',
917 sprintf( _("%s to %s"),_("English"),_("Spanish"))) .
918 translate_lang_opt('en_US', 'fr_FR', 'en|fr',
919 sprintf( _("%s to %s"),_("English"),_("French"))) .
920 translate_lang_opt('en_US', 'it_IT', 'en|it',
921 sprintf( _("%s to %s"),_("English"),_("Italian"))) .
922 translate_lang_opt('en_US', 'pt*', 'en|pt',
923 sprintf( _("%s to %s"),_("English"),_("Portuguese"))) .
924 translate_lang_opt('en_US', 'ar', 'en|ar',
925 sprintf( _("%s to %s"),_("English"),_("Arabic"))) .
926 translate_lang_opt('en_US', 'ja_JP', 'en|ja',
927 sprintf( _("%s to %s"),_("English"),_("Japanese"))) .
928 translate_lang_opt('en_US', 'ko_KR', 'en|ko',
929 sprintf( _("%s to %s"),_("English"),_("Korean"))) .
930 translate_lang_opt('en_US', 'zh_CN', 'en|zh-CN',
931 sprintf( _("%s to %s"),_("English"),_("Chinese (Simplified)"))) .
932 translate_lang_opt('de_DE', 'en_US', 'de|en',
933 sprintf( _("%s to %s"),_("German"),_("English"))) .
934 translate_lang_opt('de_DE', '', 'de|fr',
935 sprintf( _("%s to %s"),_("German"),_("French"))) .
936 translate_lang_opt('es_ES', '', 'es|en',
937 sprintf( _("%s to %s"),_("Spanish"),_("English"))) .
938 translate_lang_opt('fr_FR', '', 'fr|en',
939 sprintf( _("%s to %s"),_("French"),_("English"))) .
940 translate_lang_opt('fr_FR', '', 'fr|de',
941 sprintf( _("%s to %s"),_("French"),_("German"))) .
942 translate_lang_opt('it_IT', '', 'it|en',
943 sprintf( _("%s to %s"),_("Italian"),_("English"))) .
944 translate_lang_opt('pt*', '', 'pt|en',
945 sprintf( _("%s to %s"),_("Portuguese"),_("English"))).
946 translate_lang_opt('ar', '', 'ar|en',
947 sprintf( _("%s to %s"),_("Arabic"),_("English"))).
948 translate_lang_opt('ja_JP', '', 'ja|en',
949 sprintf( _("%s to %s"),_("Japanese"),_("English"))).
950 translate_lang_opt('ko_KR', '', 'ko|en',
951 sprintf( _("%s to %s"),_("Korean"),_("English"))).
952 translate_lang_opt('zh_CN', '', 'zh-CN|en',
953 sprintf( _("%s to %s"),_("Chinese (Simplified)"),_("English")));
954 echo '</select>'.
955 '<input type="hidden" name="hl" value="en" />' .
956 '<input type="hidden" name="ie" value="UTF8" />' .
957 '<input type="hidden" name="oe" value="UTF8" />' .
958 'Google: <input type="submit" value="' . _("Translate") . '" />';
959
960 translate_table_end();
961 }