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