Changeset 3715
- Timestamp:
- 2003-01-28T10:01:25+13:00 (21 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/picklanguage.pl
r3632 r3715 39 39 use GDBM_File; 40 40 use CGI; 41 41 use utf8; 42 42 43 43 sub main … … 71 71 open(HTMLFILE, ">$dir/picklanguage.lang") or die "MURGH\n"; 72 72 73 print HTMLFILE ("<center><strong><br>\n", 74 "Welcome to the Greenstone Language Translation Facility</strong><p>\n", 73 print HTMLFILE (" _textinitial_ <br>\n", 75 74 "<table border=\"2\" cellpadding=\"8\"><tr><td><center>", 76 " Please select a base language from which to translate:<p>\n",75 "_textselectbase_ <p>\n", 77 76 $query->popup_menu(-name=>"baselanguage", 78 77 -values=>\@languages, 79 78 -default=>'english'), 80 79 "<p></center></td><td><center>\n", 81 " Please select the language you are translating into:<p>\n",80 "_textselectforeign_ <p>\n", 82 81 $query->popup_menu(-name=>"language", 83 82 -values=>\@languages), 84 83 "<p>\n", 85 " Or enter the name of a new language:<p>\n",84 "_textselectnew_ <p>\n", 86 85 $query->textfield(-name=>"ownchoice", 87 86 -default=>"", 88 87 -size=>50), 89 88 "<p></center></td></tr></table>\n", 90 $query->submit("submitlanguage","CONTINUE >>"), 91 "</center><br>\n"); 89 $query->submit("submitlanguage","_textenter_"), 90 "</center><p>\n", 91 "<img src=\"_httpimg_/divb.gif\"><p>"); 92 92 93 93 close HTMLFILE; 94 95 open (VISITEDPAGES, ">$dir/oldpages.log") or die "MURGH\n"; 96 97 print VISITEDPAGES ""; 98 99 close VISITEDPAGES; 94 100 } 95 101 -
trunk/gsdl/bin/script/submit_translation.pl
r3632 r3715 42 42 use File::Basename; 43 43 use GDBM_File; 44 use utf8; 44 45 45 46 sub main … … 76 77 my ($macronames) = &parseusersubmission($filename); 77 78 78 foreach $key (keys %macronames) { 79 foreach $key (keys %$macronames) { 80 #print STDERR "$key\n"; 79 81 if ($key =~ m/(_\w+_)/) { 80 $macronames {$key} = " [l=$langcode] {" . $macronames{$key} . "}\n";82 $macronames->{$key} = " [l=$langcode] {" . $macronames->{$key} . "}\n"; 81 83 $macro = $key; 82 84 $macro =~ s/.*:://; 83 85 if ($macronumbered{$macro}) { 84 86 $number = $macronumbered{$macro}; 85 $foreign{$number} = $macro . $macronames {$key};87 $foreign{$number} = $macro . $macronames->{$key}; 86 88 } 87 89 } 88 90 else { 89 $macronames {$key} =~ s/\<br\>/\n/g;91 $macronames->{$key} =~ s/\<br\>/\n/g; 90 92 $macro = $key; 91 93 $macro =~ s/.*:://; 92 94 if ($macronumbered{$macro}) { 93 95 $number = $macronumbered{$macro}; 94 $foreign{$number} = $macronames {$key};96 $foreign{$number} = $macronames->{$key}; 95 97 } 96 98 } … … 99 101 $language2 = $language . "2"; 100 102 101 open MACROOUT, ">$ENV{'GSDLHOME'}/macros/$language.dm" or die "MURGH \n";103 open MACROOUT, ">$ENV{'GSDLHOME'}/macros/$language.dm" or die "MURGH MACROOUT1\n"; 102 104 103 105 foreach $ky (sort {$a <=> $b} keys %foreign) { 104 106 if ($foreign{$ky} =~ m/package\s*home/) { 105 107 close MACROOUT; 106 open MACROOUT, ">$ENV{'GSDLHOME'}/macros/$language2.dm" or die "MURGH \n";108 open MACROOUT, ">$ENV{'GSDLHOME'}/macros/$language2.dm" or die "MURGH MACROOUT2\n"; 107 109 } 108 110 print MACROOUT "$foreign{$ky}\n"; 109 111 #print STDERR "$foreign{$ky}\n"; 110 112 } 111 113 … … 122 124 $language = shift (@_); 123 125 124 open(LANGFILE, "<$ENV{'GSDLHOME'}/tmp/lang/package_forms/languages.log") or die "MURGH \n";126 open(LANGFILE, "<$ENV{'GSDLHOME'}/tmp/lang/package_forms/languages.log") or die "MURGH LANGFILE\n"; 125 127 126 128 while (<LANGFILE>) { … … 143 145 $file = shift(@_); 144 146 145 open (BASEIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or die("MURGH\n");147 open (BASEIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or return; 146 148 147 149 while (<BASEIN>) { … … 182 184 $macronumbered{$key} = $number; 183 185 } 186 #print STDERR "$file $line\n"; 184 187 } 185 188 … … 194 197 $file = shift(@_); 195 198 196 open (MACROIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or die("MURGH\n");199 open (MACROIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or return; 197 200 198 201 … … 279 282 280 283 #opens the args file or kills program 281 open(ARGUMENTS, "<$filename") or die(" Did not open $filename\n");284 open(ARGUMENTS, "<$filename") or die("MURGH USER SUBMISSION\n"); 282 285 #while there are still lines left to read 283 286 while (<ARGUMENTS>) { … … 286 289 #chomps off the final newline character 287 290 chomp($line); 288 291 289 292 #if the line contains :: (browser converts to %3A%3A) then it has a macroname 290 293 if ($line =~ m/%3A%3A/) { … … 327 330 328 331 } 329 332 #print STDERR "$key\n"; 330 333 $macronames{$key} = $macrotext; 331 334 $macrotext = ""; … … 345 348 $combined{$key} = $hash1->{$key}; 346 349 } 347 foreach $key ( keys %$hash2) {350 foreach $key (sort keys %$hash2) { 348 351 $combined{$key} = $hash2->{$key}; 352 #print STDERR "$key\n"; 349 353 } 350 354 -
trunk/gsdl/bin/script/translator.pl
r3632 r3715 39 39 use GDBM_File; 40 40 use CGI; 41 require utf8; 42 use unicode; 41 43 42 44 sub main … … 44 46 #gets the name of the language that is being translated from base language 45 47 my $file = shift(@_); 46 47 48 my $baselanguage = shift(@_); 48 49 49 50 #checks that argument was supplied 50 51 if (!$file) { 51 52 die "You didn't supply the name of the language file! Aborting...\n"; 52 53 } 54 55 my ($diffhash) = &initial_hashing($file, $baselanguage); 56 57 #generates HTML code to display user interface on webpage with what needs translation 58 #returns an array of CGI data 59 60 my @queries = &generate_pages($diffhash, $file, $baselanguage); 61 62 } 63 64 sub initial_hashing { 65 66 my ($file, $baselanguage) = @_; 67 53 68 $file = "port" if ($file =~ m/portuguese/); 54 69 $file = "indo" if ($file =~ m/indonesian/); … … 68 83 my $macrodir = "$ENV{'GSDLHOME'}/macros/"; 69 84 70 85 # always do this update because english.dm changes often 71 86 #hashes the macro file into form of macroname{macrotext} 72 87 my ($englhash) = &parse_macrofile($macrodir.$baselanguage.".dm"); 73 88 my ($engl2hash) = &parse_macrofile($macrodir.$baselanguage."2.dm"); 74 $englhash = &combine_hashes($englhash,$engl2hash); 75 89 76 90 &file_to_db($baselanguage, $englhash); 91 &file_to_db($baselanguage."2", $engl2hash); 77 92 78 93 my ($base) = &dateannotation($baselanguage); 79 94 my ($base2) = &dateannotation($baselanguage."2"); 80 95 $base = &combine_hashes($base,$base2); 81 96 82 97 # language macro-filename and database-filename 83 98 my $macrofile = $macrodir.$file.".dm"; … … 89 104 "home", "homehelp", "extlink", "authen", "collector", "docs", "usersedituser", 90 105 "usersdeleteuser", "bsummary", "status", "users", "gsdl", "userschangepasswd", 91 "userschangepasswdok" );106 "userschangepasswdok", "translang"); 92 107 93 108 open MCROFILE, ">$macrofile" or die "MURGH\n"; … … 120 135 close LANGFILE; 121 136 } 137 122 138 123 139 # if it doesn't have a database file then create one afresh … … 125 141 $macrofile = $macrodir.$file."2.dm"; 126 142 my ($langhash2) = &parse_macrofile($macrofile); 127 $langhash = &combine_hashes($langhash, $langhash2); 128 143 129 144 &file_to_db($file, $langhash); 130 145 &file_to_db($file."2", $langhash2); 146 131 147 my $foreign = &dateannotation($file); 132 148 my $foreign2 = &dateannotation($file . "2"); 133 149 $foreign = &combine_hashes($foreign, $foreign2); 134 150 135 151 #finds the differences between the english database (base language) 136 152 #and the supplied languages database and hashes these differences 137 153 #in the form macroname{macrotext} 138 154 my $diffhash = &db_db_diffs($gdbmdir.$baselanguage.".db", $dbfile, $base, $foreign, $baselanguage); 139 #generates HTML code to display user interface on webpage with what needs translation 140 #returns an array of CGI data 141 142 $file = "indonesian" if ($file =~ m/indo/); 143 $file = "portuguese" if ($file =~ m/port/); 144 145 my @queries = &generate_pages($diffhash, $file, $baselanguage); 146 147 } 155 $dbfile = $gdbmdir.$file."2.db"; 156 my $diffhash2 = &db_db_diffs($gdbmdir.$baselanguage."2.db", $dbfile, $base, $foreign, $baselanguage); 157 158 $diffhash = &combine_diffhash($diffhash,$diffhash2); 159 160 #open DIFFILE, ">$ENV{'GSDLHOME'}/tmp/lang/diffhash.log" or die "MURGH\n"; 161 162 #foreach $key (keys %$diffhash) { 163 #print DIFFILE "$key\n$diffhash->{$key}\n"; 164 #print STDERR "$key\n$diffhash->{$key}\n"; 165 #} 166 167 #close DIFFILE; 168 169 return (\%$diffhash); 170 } 171 148 172 149 173 sub combine_hashes { … … 152 176 my %combined = (); 153 177 154 foreach $key ( keys %$hash1) {178 foreach $key (sort (keys %$hash1)) { 155 179 $combined{$key} = $hash1->{$key}; 156 180 } 157 foreach $key ( keys %$hash2) {181 foreach $key (sort (keys %$hash2)) { 158 182 $combined{$key} = $hash2->{$key}; 183 } 184 185 return (\%combined); 186 187 } 188 189 sub combine_diffhash { 190 191 my ($hash1, $hash2) = @_; 192 my %combined = (); 193 194 foreach $key (sort (keys %$hash1)) { 195 $combined{$key} = [$hash1->{$key},"1"]; 196 } 197 foreach $key (sort (keys %$hash2)) { 198 $combined{$key} = [$hash2->{$key},"2"]; 159 199 } 160 200 … … 201 241 $macrotext .= $_; 202 242 #hashes the macroname and the macrotext 243 #$macrotext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 244 #&unicode::ascii2utf8($macrotext); 203 245 $macros{$key} = $macrotext; 246 247 #print STDERR "MACROTEXT $macrotext\n" if ($filename =~ m/french/); 204 248 } 205 249 #line in format ## "sometext" ## macro ## macroname ## … … 207 251 my $macroname = $_; 208 252 #saves the day/month/year 209 my $macrotext = $date[3]. "/" . $date[4] . "/" . $date[5] ."\n";253 my $macrotext = " ".$date[3]. "/" . $date[4] . "/" . $date[5] ."\n"; 210 254 211 255 unless ($macroname =~ m/^\#\# .*\#\#/) { … … 232 276 } 233 277 278 #$macrotext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 279 #&unicode::ascii2utf8($macrotext); 234 280 $macros{$key} = $macrotext; 235 281 } … … 237 283 } 238 284 close IN; 285 239 286 240 287 return (\%macros); … … 248 295 $file = qx/cd $ENV{'GSDLHOME'}\/macros;cvs annotate $language.dm/; 249 296 @file = split(/\n/,$file); 297 $file = ""; 250 298 251 299 for ($p = 0; $p < scalar(@file); $p++) { … … 259 307 260 308 if ($line =~ m/\#\# .*/) { 261 309 262 310 unless ($line =~ m/\A\#\# .*\#\#/) { 263 311 $line = $file[++$p]; … … 281 329 $macrodated{$line} = $date; 282 330 } 331 332 283 333 } 284 334 … … 295 345 # has been made generic so that other database files can be 296 346 # updated if the need arises in the future. 347 297 348 sub file_to_db 298 349 { … … 307 358 tie(%dbhash, 'GDBM_File', $database, 1, 0640) or die "$!"; 308 359 309 foreach $filekey (sort(keys(%$filehash))) { 360 foreach $filekey (sort keys(%$filehash)) { 361 #utf8::encode($foreigntext); 362 #Encode::encode_utf8($foreigntext); 363 364 # ISO 8859-1 to UTF-8 365 #print STDERR "1 $foreigntext\n"; 366 #$filehash->{$filekey} =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 367 #&unicode::ascii2utf8($filehash->{$filekey}); 368 369 #print STDERR "FILEHASH $filehash->{$filekey}\n"; 370 # UTF-8 to ISO 8859-1 371 #s/([\xC2\xC3])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg; 372 373 #$foreigntext = &unicode::ascii2utf8($foreigntext); 374 #print STDERR "2 $foreigntext\n"; 375 310 376 if (!($dbhash{$filekey})) { 311 377 $dbhash{$filekey} = $filehash->{$filekey}; … … 324 390 } 325 391 } 392 326 393 } 327 394 else { # create the database file for the particular language file... … … 361 428 tie(%db2hash, "GDBM_File", $db_two, GDBM_READER, 0640); 362 429 430 363 431 #the key is the name of the macro 364 foreach $key (sort(keys(%db1hash))) { 432 foreach $key (sort keys(%db1hash)) { 433 365 434 #if the macro isn't there at all, then it's different 366 435 if (!$db2hash{$key}) { 367 $diffhash{$key} = [$db1hash{$key}, "",""];436 $diffhash{$key} = [$db1hash{$key}, "", ""]; 368 437 } 369 438 #else if the macro is in both, want to compare date stamps of date hashes HERE 370 439 #and if foreign date is older than base date want to add to diffhash aswell 371 440 else { 441 #print STDERR "$db_one $db_two DATE $key\n"; 372 442 $macro = $key; 373 443 $macro =~ s/\A.*:://; 374 444 $bdate = $basedates->{$macro}; 375 $fdate = $foreigndates->{$macro}; 376 @bdate = split(/-/,$bdate); 377 @fdate = split(/-/,$fdate); 378 if ($bdate[2] >= $fdate[2]) { 379 if ($months{$bdate[1]} >= $months{$fdate[1]}) { 380 if ($bdate[0] > $fdate[0]) { 381 $foreigntext = $db2hash{$key}; 382 $foreigntext =~ s/^.*\n//; 383 $foreigntext =~ s/.*\{//; 384 $foreigntext =~ s/\}\Z//; 385 386 $file = qx/cd $ENV{'GSDLHOME'}\/macros;cvs diff -D $fdate $baselanguage.dm/; 387 $file .= qx/cd $ENV{'GSDLHOME'}\/macros;cvs diff -D $fdate $baselanguage"2.dm"/; 388 @file = split(/\n/,$file); 389 390 $found = 1; 391 foreach $key (@file) { 392 if ($key =~ m/$macro/) { 393 if ($key =~ m/\A</) { 394 $key =~ s/\A<\s*(_\w+_)\s*\{//; 395 $key =~ s/\}\Z//; 396 print STDERR "KEY>>>>>||||| $key\n"; 397 } 398 $found = 0; 399 } 445 $fdate = ""; 446 if ($foreigndates->{$macro}) { 447 $fdate = $foreigndates->{$macro}; 448 @fdate = split(/-/,$fdate); 449 @bdate = split(/-/,$bdate); 450 451 if ($bdate[2] >= $fdate[2]) { 452 if ($months{$bdate[1]} >= $months{$fdate[1]}) { 453 if ($bdate[0] > $fdate[0]) { 454 $foreigntext = $db2hash{$key}; 455 $foreigntext =~ s/^.*\n//; 456 $foreigntext =~ s/.*\{//; 457 $foreigntext =~ s/\}\Z//; 458 459 #$file = qx/cd $ENV{'GSDLHOME'}\/macros;cvs diff -D $fdate $baselanguage.dm/; 460 #$file .= qx/cd $ENV{'GSDLHOME'}\/macros;cvs diff -D $fdate $baselanguage"2.dm"/; 461 #@file = split(/\n/,$file); 462 463 #$found = 1; 464 #foreach $key (@file) { 465 # if ($key =~ m/$macro/) { 466 # if ($key =~ m/\A</) { 467 # $key =~ s/\A<\s*(_\w+_)\s*\{//; 468 # $key =~ s/\}\Z//; 469 # print STDERR "KEY>>>>>||||| $key\n"; 470 # } 471 # $found = 0; 472 # } 473 #} 474 #print STDERR "NOTFOUND $macro\n" if ($found); 475 476 #print STDERR "$bdate $fdate $foreigntext\n"; 477 478 #utf8::encode($foreigntext); 479 #Encode::encode_utf8($foreigntext); 480 481 # ISO 8859-1 to UTF-8 482 #print STDERR "1 $foreigntext\n"; 483 #$foreigntext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 484 #&unicode::ascii2utf8($foreigntext); 485 486 #print STDERR "FOREIGN TEXT $foreigntext\n"; 487 # UTF-8 to ISO 8859-1 488 #s/([\xC2\xC3])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg; 489 490 #$foreigntext = &unicode::ascii2utf8($foreigntext); 491 #print STDERR "2 $foreigntext\n"; 492 #print STDERR "HERE $key\n"; 493 494 $diffhash{$key} = [$db1hash{$key}, $foreigntext,""]; 400 495 } 401 print STDERR "NOTFOUND $macro\n" if ($found);402 403 $diffhash{$key} = [$db1hash{$key}, $foreigntext,""];404 496 } 405 497 } 406 498 } 407 } 408 } 409 499 else { 500 #print STDERR "THERE $key\n"; 501 $foreigntext = $db2hash{$key}; 502 #$foreigntext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 503 #&unicode::ascii2utf8($foreigntext); 504 $foreigntext =~ s/^.*\n//; 505 if ($foreigntext =~ m/\A\#\#/) { 506 $foreigntext =~ s/\A\#\#//; 507 $foreigntext =~ s/\#\#(.|\n)*//; 508 } 509 else { 510 $foreigntext =~ s/.*\{//; 511 $foreigntext =~ s/\}\Z//; 512 } 513 #print STDERR "$foreigntext\n"; 514 $diffhash{$key} = [$db1hash{$key}, $foreigntext,""]; 515 } 516 517 518 } 519 } 410 520 untie %db1hash; 411 521 untie %db2hash; 412 522 413 523 return \%diffhash; 414 } 524 } 415 525 416 526 … … 449 559 450 560 # goes through hash of differences between base language and translation 451 foreach $key (sort(keys(%$datahash))) { 561 foreach $key (sort {$datahash->{$a}[1] <=> $datahash->{$b}[1] 562 || 563 $datahash->{$a}[0] cmp $datahash->{$b}[0] } keys(%$datahash)) { 564 #print STDERR "$key\n"; 452 565 #in the hash of HTML pages, add this key to the current page and initialise it 453 566 #with it's value in the datahash 454 $pagehash->{$pageno}->{$key} = $datahash->{$key}; 567 #$datahash->{$key}[0] =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 568 #&unicode::ascii2utf8($datahash->{$key}[0]); 569 #print STDERR "DATAHASH KEY $datahash->{$key}[0]\n"; 570 $pagehash->{$pageno}->{$key} = [$datahash->{$key}[0],$datahash->{$key}[1]]; 455 571 $keysperpage++; 456 572 … … 458 574 $limit = 7 if(!($key =~ m/_.*\_/g)); 459 575 $limit = 7 if($key =~ m/help::_text.*/); 576 $limit = 1 if($key =~ m/translang::_textinitial_/); 460 577 $limit = 3 if($key =~ m/home::.*/); 461 578 $limit = 3 if($key =~ m/gsdl::.*/); 462 579 $limit = 1 if($key =~ m/help::_(.*)texthelp.*/); 463 580 $limit = $keysperpage if ($limit <= $keysperpage); 581 582 #print STDERR "$key $limit $keysperpage\n"; 464 583 465 584 #if have enough keys to generate a page with … … 501 620 #write thankyou page for language translator once translation is complete 502 621 open THANKYOU, ">$ENV{'GSDLHOME'}/tmp/lang/package_forms/thankyou.lang" or die("MURGH\n"); 503 print THANKYOU "<center> Thankyou for completing the $lang translation<p></center>\n";622 print THANKYOU "<center> _textthanks_ $lang _texttrans_ <p></center>\n"; 504 623 close THANKYOU; 505 624 … … 518 637 my $keynamecount = 1; 519 638 520 print $fh ("<center>\n", 521 "If an<font color=\"FF0000\"> UPDATED! </font>tag is present a translation already exists,<br>\n", 522 "however it's macro has since been updated.<br>\n", 523 "Please ensure that the current translation provided in the input field is correct.<br>\n", 524 $query->hidden(-name=>"hiddenlanguage",-default=>"$language"), 525 $query->hidden(-name=>"baselanguage",-default=>"$baselanguage"), 526 "<p><table border=\"5\" cellpadding=\"10\">\n", 527 "<tr><td><strong>BASE LANGUAGE FILE<br>", 528 "________________________________</strong></td>\n", 529 "<td><strong>TRANSLATED LANGUAGE<br>", 530 "________________________________</strong></td></tr>\n"); 531 532 533 foreach $key (sort(keys(%$formhash))) { 534 535 my $text = $formhash->{$key}[0]; 536 639 640 $first = "true"; 641 642 foreach $key (sort {$formhash->{$a}[1] <=> $formhash->{$b}[1]} (keys(%$formhash))) { 643 644 #print STDERR "$key\n"; 645 646 my $text = $formhash->{$key}[0][0]; 647 537 648 # whole lot of formatting on strings 538 649 # escape all the '_' with '\' so that Greenstone doesn't substitute … … 547 658 #$date = $&; 548 659 549 print STDERR "$text\n"; 550 551 552 # must take care of image macros single and multiple line ones 660 # must take care of image macros single and multiple line ones 553 661 $text =~ s/(\<br\>\#\#.*\#\#\s*\<br\>).*/$1/g; 554 662 … … 565 673 $keynamecount = 1; 566 674 567 my $default = $formhash->{$key}[1]; 568 my $updated = ""; 569 $updated = "<font color=\"FF0000\"> UPDATED! </font><br>" if ($default =~ m/\S+/); 675 #utf8::encode($foreigntext); 676 #Encode::encode_utf8($foreigntext); 677 678 # ISO 8859-1 to UTF-8 679 #$foreigntext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 680 681 # UTF-8 to ISO 8859-1 682 #s/([\xC2\xC3])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg; 683 684 #$foreigntext = &unicode::ascii2utf8($foreigntext); 685 686 my $default = $formhash->{$key}[0][1]; 687 #$default =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg; 688 #&unicode::ascii2utf8($default); 689 690 print STDERR "DEFAULT $default\n"; 691 692 my $priority = $formhash->{$key}[1]; 693 694 if($priority eq "1" and $first eq "true") { 695 696 print $fh ($query->hidden(-name=>"hiddenlanguage",-default=>"$language"), 697 $query->hidden(-name=>"baselanguage",-default=>"$baselanguage"), 698 "</center><img src=\"_httpimg_/core.gif\">", 699 "<table cellpadding=\"10\">\n", 700 "<tr><td><strong><center>".uc $baselanguage."</strong></center></td>\n", 701 "<td><strong><center>". uc $language."</strong></center></td></tr>\n"); 702 703 $first = "been"; 704 } 705 if($priority eq "2" and $first eq "true") { 706 print $fh ($query->hidden(-name=>"hiddenlanguage",-default=>"$language"), 707 $query->hidden(-name=>"baselanguage",-default=>"$baselanguage"), 708 "</center><img src=\"_httpimg_/auxiliary.gif\">", 709 "<table cellpadding=\"10\">\n", 710 "<tr><td><strong><center>". uc $baselanguage."</strong></center></td>\n", 711 "<td><strong><center>". uc $language."</strong></center></td></tr>\n"); 712 $first = "false"; 713 } 714 if($priority eq "2" and $first eq "been") { 715 print $fh ("</table><br></center><img src=\"_httpimg_/auxiliary.gif\">", 716 "<table cellpadding=\"10\">", 717 "<tr><td><strong><center>".uc $baselanguage."</strong></center></td>\n", 718 "<td><strong><center>". uc $language."</strong></center></td></tr>\n"); 719 $first = "false"; 720 } 570 721 571 722 # so that when it is an image only get the text to translate not coding stuff aswell 572 723 if ($text =~ m/\#\# (^|.)*/) { 573 724 if ($& =~ m/".*"/) { 574 print $fh ("<tr><td> $updated $&</td><td>", 725 print $fh ("<tr><td>", 726 727 $query->textfield(-name=>"whocares", 728 -default=>"$&", 729 -size=>60, 730 -readonly=>1), 731 "</td><td>", 575 732 $query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$`")); 576 733 $keynamecount++; 577 734 print $fh ($query->textfield(-name=>"$keyname" . "$keynamecount", 578 735 -default=>"$default", 579 -size=> 50));736 -size=>60)); 580 737 $keynamecount++; 581 738 print $fh ($query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$'"), … … 590 747 my $words = scalar(@words); 591 748 my $rows = sprintf("%.0f", $words/5); 592 print $fh ("<tr><td> $updated $text </td><td>\n");749 print $fh ("<tr><td>"); 593 750 if ($rows > 1) { 594 print $fh ($query->textarea(-name=>"$keyname" . "$keynamecount", 751 print $fh ($query->textarea(-name=>"whocares", 752 -rows=>$rows * 2, 753 -default=>"$text", 754 -columns=>50, 755 -readonly=>1), 756 "</td><td>", 757 $query->textarea(-name=>"$keyname" . "$keynamecount", 595 758 -rows=>$rows * 2, 596 759 -default=>"$default", … … 599 762 } 600 763 else { 601 print $fh ($query->textfield(-name=>"$keyname" . "$keynamecount", 764 print $fh ($query->textfield(-name=>"whocares", 765 -default=>"$text", 766 -size=>50, 767 -readonly=>1), 768 "</td><td>", 769 $query->textfield(-name=>"$keyname" . "$keynamecount", 602 770 -default=>"$default", 603 771 -size=>50), … … 607 775 } 608 776 #finishes table and adds a SUBMIT CHANGES option on the end 609 print $fh ("</table>\n", "<br>", 610 "Please ensure your $language translation is correct before proceeding.<br>\n", 611 "Input fields may be left empty if necessary and only those field which<br>\n", 612 "contain a translation will be submitted to the macro file.<br>\n", 613 "Submitting this page will result in the next page being loaded automatically.<br><strong>\n", 614 $query->submit($pageno, 'SUBMIT TRANSLATION >>'), 615 "</strong>","</center>\n"); 777 print $fh ("</table>\n", "<br><center>", 778 $query->submit($pageno, "_textsubmit_"), 779 "<br> _textsubmittext_ \n"); 616 780 617 781 # adds the CGI area just written to the array of CGI areas -
trunk/gsdl/src/recpt/langaction.cpp
r3638 r3715 31 31 #include "gsdlunicode.h" 32 32 #include "langdb.h" 33 #include "receptionist.h" 33 34 #include "errno.h" 34 35 #include <sys/utsname.h> 35 36 36 37 37 /*====================* … … 49 49 *========================*/ 50 50 51 void add_visited_page (text_t dir, ostream & logout, text_t pageno) { 52 53 text_tarray oldpages; 54 bool visited = false; 55 56 // file 'logfile' contains all the page numbers, one number per line 57 text_t logfile = filename_cat(dir, "package_forms", "oldpages.log"); 58 59 //open the file as a read only file 60 ifstream readfile(logfile.getcstr(), ios::in); 61 62 // if file isn't opened, print error and return 63 if (!readfile) { 64 logout << "IN File " << logfile.getcstr() << " could not be found.\n"; 65 return; 66 } 67 68 // go through file, pushing each page number on to the end of a text_tarray 69 while (readfile.getline(temp, BUFFSIZE-1)) { 70 text_t t_temp = temp; 71 oldpages.push_back(temp); 72 if (strcmp(pageno.getcstr(),t_temp.getcstr()) == 0) { 73 visited = true; 74 } 75 } 76 readfile.close(); 77 78 if (visited == false) { 79 ofstream writefile(logfile.getcstr(), ios::out); 80 81 for (text_tarray::iterator page_itr = oldpages.begin(); 82 page_itr != oldpages.end(); 83 page_itr++) { 84 85 writefile << *page_itr <<endl; 86 } 87 time_t seconds; 88 seconds = time(NULL); 89 90 if (pageno == "2") 91 writefile << "1" <<endl; 92 93 writefile << pageno <<endl; 94 95 logout << "ADDING PAGE " << pageno.getcstr() << " " << seconds <<endl; 96 97 writefile.close(); 98 } 99 } 51 100 // gets the list of packages/files that contain the content of the web-forms 52 101 text_tarray get_pagenos(text_t dir, ostream &logout) … … 98 147 } 99 148 149 150 // set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros 151 // reponse contains 1 metadata field (Title) 152 100 153 bool langaction::init (ostream & /*logout*/) { 101 154 … … 176 229 void langaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/, 177 230 response_t &response,text_t &response_data, 178 ostream & /*logout*/) {231 ostream & logout) { 179 232 response = content; 180 233 response_data = "text/html"; … … 183 236 void langaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 184 237 recptprotolistclass *protos, ostream &logout) { 238 185 239 text_t text = ""; 186 240 text_t cmd = ""; … … 190 244 text_t pageno =""; 191 245 text_t lang = ""; 246 text_t baselanguage = ""; 247 248 //creates output stream to argsfile (dir is gsdlhome/tmp/lang) 249 text_t argsfile = filename_cat(dir, "arguments.arg"); 250 ofstream argsout(argsfile.getcstr(), ios::out); 251 252 //informs user and returns if output stream not opened 253 if(!argsout) { 254 logout << "File " << argsfile.getcstr() << " could not be opened\n"; 255 return; 256 } 257 258 //ensures access permissions make the file world writable 259 text_t changemode = "chmod a+w "; 260 changemode += argsfile; 261 gsdl_system(changemode, false, logout); 262 263 //write out the cgiargsclass passes as a parameter to the subroutine to the argsout file 264 argsout << args; 265 266 // utf8outconvertclass text_tutf8; 267 268 // for (cgiargsclass::iterator args_itr = args.begin(); 269 // args_itr != args.end(); 270 // args_itr++) { 271 272 // if(text_t_substring(*args_itr->first, pageno, logout)) { 273 // argsout << text_t2utf8 << "\"" << args_itr->first << "\"=\n\"" 274 // << (args_itr->second).value << "\"\n"; 275 // } 276 // } 277 278 //close the argsout output stream 279 argsout.close(); 280 281 if (args["nextlink"] != "") { 282 add_visited_page(dir,logout,args["nextlink"]); 283 } 284 285 //sets the current foreign language 286 if (args["ownchoice"] != "") { 287 lang = args["ownchoice"]; 288 } 289 else if (args["hiddenlanguage"] != "") { 290 lang = args["hiddenlanguage"]; 291 } 292 else { 293 lang = args["language"]; 294 } 295 296 //sets current base language 297 if (args["baselanguage"] != "") { 298 baselanguage = args["baselanguage"]; 299 } 192 300 193 301 // argument for page is of the form 'macrofile_pageno' so … … 199 307 if (splitarray.size() > 1) 200 308 pageno = splitarray[splitarray.size()-1]; 201 202 if (pageno == "picklanguage") 309 310 if (pageno == "fromsearch") { 311 text_t macroname = args["macroname"]; 312 text_t macrotext = args["macrotext"]; 313 314 logout << "macro data " << macroname.getcstr() << macrotext.getcstr() <<endl; 315 316 //calls the translator file to create HTML files 317 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "fromsearch.pl") + " " + macroname + " " + macrotext; 318 logout << "COMMAND: " << cmd.getcstr() <<endl; 319 320 if ((gsdl_system(cmd, true, logout)) != 0) { 321 logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 322 return; 323 } 324 325 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 326 return; 327 } 328 329 if (pageno == "picklanguage") { 203 330 pageno = "1"; 204 205 if (pageno.empty()) 331 332 //calls the translator file to create HTML files 333 // cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "translator.pl") + " " + lang + " " + baselanguage; 334 // if ((gsdl_system(cmd, true, logout)) != 0) { 335 // logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 336 // return; 337 // } 338 } 339 340 //generates the picklanguage page 341 if (pageno.empty()) { 206 342 pageno = "picklanguage"; 207 208 //produce the picklanguage webpage 209 if (pageno == "picklanguage") { 343 logout << "@ the 1st pg\n"; 210 344 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "picklanguage.pl"); 345 logout << cmd.getcstr() << " PICKLANGUAGE\n" <<endl; 211 346 if(gsdl_system(cmd,true,logout) != 0) 212 347 return; 213 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text); 348 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 349 214 350 return; 215 351 } 216 217 //creates output stream to argsfile (dir is gsdlhome/tmp/lang) 218 text_t argsfile = filename_cat(dir, "arguments.arg"); 219 ofstream argsout(argsfile.getcstr(), ios::out); 220 221 //informs user and returns if output stream not opened 222 if(!argsout) { 223 logout << "File " << argsfile.getcstr() << " could not be opened\n"; 224 return; 225 } 226 227 //ensures access permissions make the file world writable 228 text_t changemode = "chmod a+w "; 229 changemode += argsfile; 230 gsdl_system(changemode, false, logout); 231 232 //write out the cgiargsclass passes as a parameter to the subroutine to the argsout file 233 argsout << args; 234 235 //close the argsout output stream 236 argsout.close(); 237 238 //sets the current foreign language 239 if (args["ownchoice"] != "") { 240 lang = args["ownchoice"]; 241 } 242 else if (args["hiddenlanguage"] != "") { 243 lang = args["hiddenlanguage"]; 244 } 245 else { 246 lang = args["language"]; 247 } 248 text_t baselanguage = ""; 249 250 //sets current base language 251 if (args["baselanguage"] != "") { 252 baselanguage = args["baselanguage"]; 253 } 254 255 256 //calls the translator file to create HTML files 257 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "translator.pl") + " " + lang + " " + baselanguage; 258 259 if ((gsdl_system(cmd, true, logout)) != 0) { 260 logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 261 return; 262 } 263 352 264 353 //if no more pages will set pageno to thankyou script 265 354 pagenos = get_pagenos(dir,logout); 266 if (pagenos.empty()) 355 356 if (pagenos.empty() && pageno == "") 267 357 pageno = "thankyou"; 268 269 358 270 359 text_t &submitargs = args[pageno]; 271 text_t submit = "SUBMIT TRANSLATION >>";360 text_t submit = "SUBMIT TRANSLATION"; 272 361 273 362 //if the SUBMIT TRANSLATION >> button has been pushed … … 286 375 page_itr != pagenos.end(); 287 376 page_itr++) { 288 377 logout << pageno.getcstr() << " page number before" <<endl; 378 289 379 if (*page_itr == pageno) { 290 380 page_itr++; … … 296 386 break; 297 387 } 388 389 logout << pageno.getcstr() << " page number after" <<endl; 298 390 } 299 } 300 //want it to automatically load the next page here instead of reloading page 301 //that has just been translated with everything empty again. 302 303 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text); 391 add_visited_page(dir,logout,pageno); 392 } 393 394 pagenos = get_pagenos(dir,logout); 395 logout << "PAGENOS... " << pagenos.size() <<endl; 396 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 304 397 } 305 398 306 399 void langaction::define_webpage (displayclass &disp, 307 400 recptprotolistclass *protos, ostream &logout, 308 text_t &pageno, text_t &lang, text_t &dir,309 text_tarray &pagenos, text_t &text ) {401 text_t pageno, text_t &lang, text_t &dir, 402 text_tarray &pagenos, text_t &text, text_t &baselanguage) { 310 403 311 404 // produces HTML page with the current pages contents … … 324 417 325 418 /* ============================ START WEB-FORM HTML CODE ============================ */ 419 text += "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>"; 420 326 421 text += "\n<input type=hidden name=\"a\" value=\"lang\">"; 327 422 text += "\n<input type=hidden name=\"p\" value=\"translang_"; … … 329 424 text += "\">\n"; 330 425 331 text += "<strong><br>\n"; 332 text += "</center><img src=\"_httpimg_/gsdlhead.gif\"><center><p>"; 333 text += "<img src=\"_httpimg_/divb.gif\"><p>"; 334 text += "<font size=\"7\">Greenstone Language Translation Facility</font></strong><p>\n"; 335 426 text += "_texttranshead_"; 427 336 428 337 429 //if not a special case page display translation info 338 430 if ((pageno != "thankyou") && (pageno !="picklanguage")) { 339 text += "<center><strong>You are currently translating page "; 431 432 logout << "PAGENOS " << pagenos.size() <<endl; 433 434 text += "<center><strong> _textcurrpage_ "; 340 435 text += pageno; 341 text += " of";436 text += " _textof_ "; 342 437 text += pagenos.size(); 343 text += " in to ";344 text += lang;345 438 text += "</strong></center><p><p>\n"; 346 439 } 347 440 441 utf8outconvertclass text_tutf8; 442 348 443 //read in HTML from file 349 444 while(readfile.getline(temp, BUFFSIZE-1)) { 350 445 text_t t_temp = temp; 351 446 text += t_temp; 447 448 //logout << t_temp.getcstr() <<endl; 449 450 // text_t2utf8.setinput(&t_temp); 451 // char *buffer = new char[t_temp.size()]; 452 // size_t num_chars; 453 // convertclass::status_t status; 454 // text_t2utf8.convert(buffer, t_temp.size(), num_chars, status); 455 // logout << buffer <<endl; 456 // delete buffer; 457 458 // for (cgiargsclass::iterator args_itr = args.begin(); 459 // args_itr != args.end(); 460 // args_itr++) { 461 462 // if(text_t_substring(*args_itr->first, pageno, logout)) { 463 // argsout << text_t2utf8 << "\"" << args_itr->first << "\"=\n\"" 464 // << (args_itr->second).value << "\"\n"; 465 // } 466 // } 467 468 // logout << t_temp.getcstr() <<endl; 352 469 text += "\n"; 353 470 } … … 356 473 //if not a special case page display translation info 357 474 if ((pageno != "thankyou") && (pageno != "picklanguage")) { 358 text += "<center><strong> You are currently translating page";475 text += "<center><strong> _textcurrpage_ "; 359 476 text += pageno; 360 text += " of";477 text += " _textof_ "; 361 478 text += pagenos.size(); 362 text += " in to "; 363 text += lang; 364 text += "</strong></center><br>\n"; 479 text += "</strong><br>\n"; 480 481 482 text_tarray oldpages; 483 484 // file 'logfile' contains all the page numbers, one number per line 485 text_t logfile = filename_cat(dir, "package_forms", "oldpages.log"); 486 487 //open the file as a read only file 488 ifstream reader(logfile.getcstr(), ios::in); 489 490 // if file isn't opened, print error and return 491 if (!reader) { 492 logout << "IN File " << logfile.getcstr() << " could not be found.\n"; 493 } 494 495 // go through file, pushing each page number on to the end of a text_tarray 496 while (reader.getline(temp, BUFFSIZE-1)) { 497 text += "<a href=\"_gwcgi_?a=lang&p=translang_"; 498 text += temp; 499 text += "&baselanguage="; 500 text += baselanguage; 501 text += "&language="; 502 text += lang; 503 text += "\"><strong>"; 504 text += temp; 505 text += "</strong></a>\n"; 506 507 } 508 509 text_t temp2 = ""; 510 511 for (text_tarray::iterator page_itr = pagenos.begin(); 512 page_itr != pagenos.end(); 513 page_itr++) { 514 515 logout << "TEMP2 " << temp2.getcstr() <<endl; 516 logout << "PAGENO " << pageno.getcstr() <<endl; 517 518 if (*page_itr == pageno) { 519 page_itr++; 520 if (page_itr != pagenos.end()) 521 temp2 = *page_itr; 522 else 523 temp2 = "thankyou"; 524 525 logout << "TEMP2 " << temp2.getcstr() <<endl; 526 logout << "PAGENO " << pageno.getcstr() <<endl; 527 528 break; 529 } 530 } 531 532 text += "<a href=\"_gwcgi_?a=lang&p=translang_"; 533 text += temp2; 534 text += "&baselanguage="; 535 text += baselanguage; 536 text += "&language="; 537 text += lang; 538 text += "&nextlink="; 539 text += pageno; 540 text += "\"><strong>"; 541 text += "NEXT>>"; 542 text += "</strong></a>\n"; 543 544 text += "</body></html>\n"; 545 546 reader.close(); 365 547 } 366 367 368 548 /* ============================ END WEB-FORM HTML CODE ============================ */ 549 369 550 370 551 // THE FOLLOWING MACROS ARE DEFINED IN translang.dm MACRO FILE … … 375 556 // disp.setmacro("formaction", "translang", "/cgi-bin/dg5/library"); 376 557 disp.setmacro("formaction", "translang", "_gwcgi_"); 558 559 text_t navigationbar = "<!-- Navigation Bar -->\n"; 560 navigationbar += "<table width=\"100%\" cellspacing=0 cellpadding=0>"; 561 navigationbar += "<tr valign=top><td rowspan=2 align=left>_imagecollection_</td>"; 562 navigationbar += "<td align=right>_javalinks_</td><td>"; 563 navigationbar += "_imageserch_</td></tr></table>"; 564 navigationbar += "\n</nobr>\n"; 565 navigationbar += "<!-- End of Navigation Bar -->\n"; 566 disp.setmacro ("navigationbar", "translang", navigationbar); 377 567 378 568 } … … 388 578 << ("_" + arg_p + ":footer_\n"); 389 579 580 logout << outconvert << disp << ("_" + arg_p + ":header_\n"); 581 390 582 return true; 391 583 } 392 584 393 585 394 395 -
trunk/gsdl/src/recpt/langaction.h
r3632 r3715 65 65 void define_webpage (displayclass &disp, 66 66 recptprotolistclass *protos, ostream &logout, 67 text_t &pageno, text_t &lang, text_t &dir,68 text_tarray &pagenos, text_t &text );67 text_t pageno, text_t &lang, text_t &dir, 68 text_tarray &pagenos, text_t &text, text_t &baselanguage); 69 69 70 70 71 71 }; 72 72
Note:
See TracChangeset
for help on using the changeset viewer.