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