Changeset 4129
- Timestamp:
- 2003-04-11T16:41:30+12:00 (21 years ago)
- Location:
- trunk/gsdl/bin/script
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/submit_translation.pl
r4125 r4129 38 38 39 39 40 use util; 40 41 use GDBM_File; 41 42 … … 69 70 $targetlang =~ tr/A-Z/a-z/; 70 71 71 my $gsdldir = "$ENV{'GSDLHOME'}/"; 72 my $translationdir = $gsdldir . "tmp/lang/" . $sourcelang . "-" . $targetlang . "/"; 73 my $translationdb = $translationdir . "translation.db"; 74 my $updatedb = $translationdir . "update.db"; 72 my $gsdldir = "$ENV{'GSDLHOME'}"; 73 my $langdir = util::filename_cat($gsdldir, "tmp", "lang"); 74 my $translationdir = util::filename_cat($langdir, $sourcelang . "-" . $targetlang); 75 my $translationdb = util::filename_cat($translationdir, "translation.db"); 76 my $updatedb = util::filename_cat($translationdir, "update.db"); 75 77 76 78 # Open the two database files for the translation … … 79 81 80 82 # Parse the translation submissions 81 my $submissions = &parse_user_submission($sourcelang, $targetlang, 82 $translationdir.$argsfile); 83 my $targetcode = $translationdata{"*target_lang_code*"}; 84 my $submissions = &parse_user_submission($sourcelang, $targetlang, $targetcode, 85 util::filename_cat($translationdir, $argsfile)); 83 86 # print "Submissions:\n"; 84 87 # &display_hash($submissions); … … 88 91 89 92 # Writes the target macro files 90 my $macrosdir = $gsdldir . "macros/";93 my $macrosdir = util::filename_cat($gsdldir, "macros"); 91 94 &write_target_macro_files($sourcelang, $targetlang, $macrosdir); 95 96 # Generate all the images for both macro files 97 # my $imagesdir = util::filename_cat($gsdldir, "images", $targetcode); 98 # my $scriptdir = util::filename_cat($gsdldir, "bin", "script"); 99 100 # my $targetdmfile1 = util::filename_cat($macrosdir, $targetlang . ".dm"); 101 # my $genimagescmd1 = "perl " . util::filename_cat($scriptdir, "translate.pl") . 102 # " -language_symbol $targetcode -image_dir $imagesdir $targetdmfile1"; 103 # $genimagescmd1 = "cd $gsdldir ; source setup.bash ; $genimagescmd1"; 104 # open SUBMIT_SCRIPT_1, ">" . util::filename_cat($translationdir, "submit1.tmp"); 105 # print SUBMIT_SCRIPT_1 "$genimagescmd1\n"; 106 # close SUBMIT_SCRIPT_1; 107 108 # my $targetdmfile2 = util::filename_cat($macrosdir, $targetlang . "2.dm"); 109 # my $genimagescmd2 = "perl -S " . util::filename_cat($scriptdir, "translate.pl") . 110 # " -language_symbol $targetcode -image_dir $imagesdir $targetdmfile2"; 111 # print STDERR "Command 2: $genimagescmd2\n"; 112 # my $result2 = system($genimagescmd2); 113 # `$genimagescmd2`; 114 # print STDERR "Result 2: $result2\n"; 92 115 93 116 # Clean up … … 99 122 sub parse_user_submission 100 123 { 101 my ($sourcelang, $targetlang, $ filename) = @_;124 my ($sourcelang, $targetlang, $targetcode, $filename) = @_; 102 125 103 126 #opens the args file or kills program … … 106 129 #stores a hash of macronames with numbers still appended and their values 107 130 my %distinctkeys = (); 131 my %icontextvals = (); 108 132 109 133 #while there are still lines left to read … … 120 144 # print "Line: $line\n"; 121 145 146 # Does the line contain a new CGI argument? 122 147 if ($line =~ m/^ \"/) { 123 # if the line contains :: (browser converts to %3A%3A) then it has a macroname148 # If the line contains :: (browser converts to %3A%3A) then it has a macroname 124 149 if ($line =~ m/%3A%3A/) { 125 150 #hashes the previous macro and its value, provided the value is non-empty 126 151 if ($macrovalue =~ m/\S+/) { 127 $distinctkeys{$macroname} = $macrovalue; 152 # Add the icontext macros to a separate list 153 if ($macroname =~ m/::icontext$/) { 154 $icontextvals{$macroname} = $macrovalue; 155 } 156 else { 157 $distinctkeys{$macroname} = $macrovalue; 158 } 128 159 } 129 160 … … 149 180 #hashes the previous macro and its value, provided the value is non-empty 150 181 if ($macroname ne "" && $macrovalue =~ m/\S+/) { 151 $distinctkeys{$macroname} = $macrovalue; 182 # Add the icontext macros to a separate list 183 if ($macroname =~ m/::icontext$/) { 184 $icontextvals{$macroname} = $macrovalue; 185 } 186 else { 187 $distinctkeys{$macroname} = $macrovalue; 188 } 152 189 } 153 190 $macroname = ""; … … 155 192 } 156 193 } 194 # No, so check if it is part of a multi-line macro 157 195 else { 158 # Check if this is part of a multi-line macro159 196 if ($macroname ne "") { 160 197 $extravalue = $line; … … 174 211 # Create a hash map containing the translations to add 175 212 my %translations = (); 176 my $targetcode = $translationdata{"*target_lang_code*"};177 213 178 214 for $sourcekey (sort keys %distinctkeys) { 179 my $macrotext = $distinctkeys{$sourcekey}; 180 $macrotext = "[l=$targetcode] {" . $macrotext . "}\n"; 215 my $macrotext = ""; 216 217 # Check if this macro is an icon macro 218 my $iconkey = $sourcekey . "::icontext"; 219 if ($icontextvals{$iconkey}) { 220 my $icontext = $icontextvals{$iconkey}; 221 222 # Add the language code to each part of the icon macro 223 # -- This is done by translate.pl when the images are created -- 224 $icontext =~ s/(\n_[^_]+_ )/$1\[l=$targetcode\] /g; 225 $icontext =~ s/( {_[^_]+_)(.*)(\/([^\/]+)})/$1\/$targetcode$3/g; 226 227 $macrotext = "## \"" . $distinctkeys{$sourcekey} . "\" " . $icontext . "\n"; 228 } 229 # It must be a text macro 230 else { 231 $macrotext = "[l=$targetcode] {" . $distinctkeys{$sourcekey} . "}\n"; 232 } 181 233 182 234 my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey); … … 256 308 my ($sourcelang, $targetlang, $macrosdir) = @_; 257 309 258 my $targetdmfile1 = $macrosdir . &get_macrofile_name($targetlang, "");259 my $targetdmfile2 = $macrosdir . &get_macrofile_name($targetlang, "2");310 my $targetdmfile1 = util::filename_cat($macrosdir, &get_macrofile_name($targetlang, "")); 311 my $targetdmfile2 = util::filename_cat($macrosdir, &get_macrofile_name($targetlang, "2")); 260 312 261 313 my $currentfile = "1"; -
trunk/gsdl/bin/script/translator.pl
r4125 r4129 331 331 } 332 332 333 # Line in format ## "sometext" ## macro ## macroname ##333 # Icon: line in format ## "sometext" ## macro ## macroname ## 334 334 elsif (/^\#\# .*/) { 335 335 my $macroname = $_; … … 360 360 # key to the hash and the database 361 361 my $key = $macrofile . "::" . $currpackage . "::" . $macroname; 362 # print "Icon, key: $key\n text: $macrotext\n"; 362 363 # hashes macroname and macrotext 363 364 $macros{$key} = $macrotext; … … 432 433 if (!$translationdata{$targetkey}) { 433 434 # print "Macro $sourcekey needs translating.\n"; 435 # print "Text to translate: $sourcehash->{$sourcekey}\n"; 434 436 $needstranslating{$sourcekey}[0] = $sourcehash->{$sourcekey}; 435 437 $needstranslating{$sourcekey}[1] = ""; … … 524 526 } 525 527 526 # Write the number of pages to a file 528 # Write the number of pages to a file for use by the receptionist 527 529 my $numpagesfile = util::filename_cat($translationdir, "numpages.log"); 528 530 open NUMPAGESLOG, ">$numpagesfile" or die "Error: Could not write $numpagesfile.\n"; … … 533 535 my $thankyoufile = util::filename_cat($translationdir, "thankyou.lang"); 534 536 open THANKYOU, ">$thankyoufile" or die "Error: Could not write $thankyoufile.\n"; 535 print THANKYOU ("<center> _textthanks_ $targetlang _texttrans_ _textgetdmfiles_ ", 536 "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>", 537 " & ", 538 "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.", 537 print THANKYOU ("<center> _textthanks_ $targetlang _texttrans_ ", 538 "<br> _textviewtranslation_ ", 539 "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.", 540 # "_textgetdmfiles_ ", 541 # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>", 542 # " & ", 543 # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.", 539 544 "<p></center>\n"); 540 545 close THANKYOU; … … 583 588 $default =~ s/(\A\n)//; 584 589 $default =~ s/(\n\Z)//; 585 # print "Key: $keyname Text: $text Default: $default\n"; 586 587 $keynamecount = 1; 588 590 591 # $keynamecount = 1; 592 589 593 #tells whether is a core or auxiliary macro 590 594 my $priority = &core_or_auxiliary_macro($sourcelang, $keyname); … … 627 631 # so that when it is an image only get the text to translate not coding stuff aswell 628 632 if ($text =~ m/\#\# (^|.)*/) { 633 # print STDERR "\nIcon -- Key: $keyname\nText: $text\n"; # Default: $default\n"; 629 634 if ($& =~ m/".*"/) { 630 635 #prints to the file two text fields, the left one contains the base language 631 636 #macro text, the right contains the translation language macro text if any exists 637 my $icontext = $&; 638 $icontext =~ s/"(.*)"/$1/; 639 # print "Text to translate: $icontext\n"; 640 641 my $remainder = $text; 642 $remainder =~ s/^\#\# ([^\#]*)//; 643 # print "Remainder: $remainder\n"; 644 645 $rows = 1; 632 646 633 647 my $textbox1; 634 648 if (1) { 635 $rows = 1; # if ($rows < 1);636 649 $textbox1 = "<textarea name=\"whocaresh\" rows=\"$rows\" cols=\"50\" readonly=\"1\">"; 637 $textbox1 .= "$ &</textarea>\n";650 $textbox1 .= "$icontext</textarea>\n"; 638 651 } 639 652 else { 640 $textbox1 = $query->textfield(-name=>"whocares", 641 -default=>"$&", 642 -size=>50, 643 -readonly=>1); 653 $textbox1 = $query->textfield(-name=>"whocares", -default=>"$icontext", 654 -size=>50, -readonly=>1); 644 655 } 645 646 print $fh ("<tr><td align=center>", $textbox1, 647 "</td><td align=center>", 648 $query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$`")); 649 $keynamecount++; 656 print $fh ("<tr><td align=center>", $textbox1, "</td><td align=center>"); 657 # $query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$`")); 658 # $keynamecount++; 650 659 651 660 my $textbox2; 652 661 if (1) { 653 $textbox2 = "<textarea name=\"$keyname $keynamecount\" rows=\"$rows\" cols=\"50\">";662 $textbox2 = "<textarea name=\"$keyname\" rows=\"$rows\" cols=\"50\">"; 654 663 $textbox2 .= "$default</textarea><br>\n"; 655 664 } 656 665 else { 657 $textbox2 = $query->textfield(-name=>"$keyname" . "$keynamecount", 658 -default=>"$default", 666 $textbox2 = $query->textfield(-name=>"$keyname", -default=>"$default", 659 667 -size=>50); 660 668 } 661 669 print $fh $textbox2; 662 $keynamecount++; 663 print $fh ($query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$'"), 664 "</td></tr>\n"); 670 671 print $fh $query->hidden(-name=>"$keyname" . "::icontext", 672 -default=>"$remainder"); 673 print $fh "</td></tr>\n"; 674 675 # $keynamecount++; 676 # print $fh ($query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$'"), 677 # "</td></tr>\n"); 665 678 } 666 679 } 680 # Text macro 667 681 elsif ($text =~ m/\S+/) { 668 682 $text =~ s/\s+/ /g; … … 719 733 $query->submit($pageno, "_textsubmit_"), 720 734 "</td></tr><tr><td width=\"50%\"></td><td align=right width=\"50%\">", 721 "<br> _textsubmittext_ ",735 "<br> _textsubmittext_ <br> _textviewtranslation_ ", 722 736 "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.", 723 737 # "_textgetdmfiles_ ",
Note:
See TracChangeset
for help on using the changeset viewer.