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