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