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