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