Changeset 3715


Ignore:
Timestamp:
2003-01-28T10:01:25+13:00 (21 years ago)
Author:
kde2
Message:

Updating Language Translation Agency

Location:
trunk/gsdl
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/picklanguage.pl

    r3632 r3715  
    3939use GDBM_File;
    4040use CGI;
    41 
     41use utf8;
    4242
    4343sub main
     
    7171    open(HTMLFILE, ">$dir/picklanguage.lang") or die "MURGH\n";
    7272   
    73     print HTMLFILE ("<center><strong><br>\n",
    74             "Welcome to the Greenstone Language Translation Facility</strong><p>\n",
     73    print HTMLFILE (" _textinitial_ <br>\n",
    7574            "<table border=\"2\" cellpadding=\"8\"><tr><td><center>",
    76             "Please select a base language from which to translate: <p>\n",
     75            "_textselectbase_ <p>\n",
    7776            $query->popup_menu(-name=>"baselanguage",
    7877                       -values=>\@languages,
    7978                       -default=>'english'),
    8079            "<p></center></td><td><center>\n",
    81             "Please select the language you are translating into: <p>\n",
     80            "_textselectforeign_ <p>\n",
    8281            $query->popup_menu(-name=>"language",
    8382                       -values=>\@languages),
    8483            "<p>\n",
    85             "Or enter the name of a new language: <p>\n",
     84            "_textselectnew_ <p>\n",
    8685            $query->textfield(-name=>"ownchoice",
    8786                      -default=>"",
    8887                      -size=>50),
    8988            "<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>");
    9292   
    9393    close HTMLFILE;
     94
     95    open (VISITEDPAGES, ">$dir/oldpages.log") or die "MURGH\n";
     96
     97    print VISITEDPAGES "";
     98
     99    close VISITEDPAGES;
    94100}
    95101
  • trunk/gsdl/bin/script/submit_translation.pl

    r3632 r3715  
    4242use File::Basename;
    4343use GDBM_File;
     44use utf8;
    4445
    4546sub main
     
    7677    my ($macronames) = &parseusersubmission($filename);
    7778
    78     foreach $key (keys %macronames) {
     79    foreach $key (keys %$macronames) {
     80    #print STDERR "$key\n";
    7981    if ($key =~ m/(_\w+_)/) {
    80         $macronames{$key} = " [l=$langcode] {" . $macronames{$key} . "}\n";
     82        $macronames->{$key} = " [l=$langcode] {" . $macronames->{$key} . "}\n";
    8183        $macro = $key;
    8284        $macro =~ s/.*:://;
    8385        if ($macronumbered{$macro}) {
    8486        $number = $macronumbered{$macro};
    85         $foreign{$number} = $macro . $macronames{$key};
     87        $foreign{$number} = $macro . $macronames->{$key};
    8688        }
    8789    }
    8890    else {
    89         $macronames{$key} =~ s/\&lt;br\&gt;/\n/g;
     91        $macronames->{$key} =~ s/\&lt;br\&gt;/\n/g;
    9092        $macro = $key;
    9193        $macro =~ s/.*:://;
    9294        if ($macronumbered{$macro}) {
    9395        $number = $macronumbered{$macro};
    94         $foreign{$number} = $macronames{$key};
     96        $foreign{$number} = $macronames->{$key};
    9597        }
    9698    }
     
    99101    $language2 = $language . "2";
    100102
    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";
    102104
    103105    foreach $ky (sort {$a <=> $b} keys %foreign) {
    104106    if ($foreign{$ky} =~ m/package\s*home/) {
    105107        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";
    107109    }
    108110    print MACROOUT "$foreign{$ky}\n";
    109    
     111    #print STDERR "$foreign{$ky}\n";
    110112    }
    111113
     
    122124    $language = shift (@_);
    123125
    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";
    125127
    126128    while (<LANGFILE>) {
     
    143145    $file = shift(@_);
    144146
    145     open (BASEIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or die("MURGH\n");
     147    open (BASEIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or return;
    146148   
    147149    while (<BASEIN>) {
     
    182184        $macronumbered{$key} = $number;
    183185    }
     186    #print STDERR "$file $line\n";
    184187    }
    185188   
     
    194197    $file = shift(@_);
    195198
    196     open (MACROIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or die("MURGH\n");
     199    open (MACROIN, "<$ENV{'GSDLHOME'}/macros/$file.dm") or return;
    197200   
    198201   
     
    279282   
    280283    #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");
    282285    #while there are still lines left to read
    283286    while (<ARGUMENTS>) {
     
    286289    #chomps off the final newline character
    287290    chomp($line);
    288    
     291
    289292        #if the line contains :: (browser converts to %3A%3A) then it has a macroname
    290293    if ($line =~ m/%3A%3A/) {
     
    327330       
    328331    }
    329    
     332    #print STDERR "$key\n";
    330333    $macronames{$key} = $macrotext;
    331334    $macrotext = "";
     
    345348    $combined{$key} = $hash1->{$key};
    346349    }
    347     foreach $key (keys %$hash2) {
     350    foreach $key (sort keys %$hash2) {
    348351    $combined{$key} = $hash2->{$key};
     352    #print STDERR "$key\n";
    349353    }
    350354
  • trunk/gsdl/bin/script/translator.pl

    r3632 r3715  
    3939use GDBM_File;
    4040use CGI;
     41require utf8;
     42use unicode;
    4143
    4244sub main
     
    4446    #gets the name of the language that is being translated from base language
    4547    my $file = shift(@_);
    46    
    4748    my $baselanguage = shift(@_);
    48 
     49   
    4950    #checks that argument was supplied
    5051    if (!$file) {
    5152    die "You didn't supply the name of the language file! Aborting...\n";
    5253    }
     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
     64sub initial_hashing {
     65
     66    my ($file, $baselanguage) = @_;
     67
    5368    $file = "port" if ($file =~ m/portuguese/);
    5469    $file = "indo" if ($file =~ m/indonesian/);
     
    6883    my $macrodir = "$ENV{'GSDLHOME'}/macros/";
    6984   
    70      # always do this update because english.dm changes often
     85    # always do this update because english.dm changes often
    7186    #hashes the macro file into form of macroname{macrotext}
    7287    my ($englhash) = &parse_macrofile($macrodir.$baselanguage.".dm");
    7388    my ($engl2hash) =  &parse_macrofile($macrodir.$baselanguage."2.dm");
    74     $englhash = &combine_hashes($englhash,$engl2hash);
    75 
     89   
    7690    &file_to_db($baselanguage, $englhash);
     91    &file_to_db($baselanguage."2", $engl2hash);
    7792   
    7893    my ($base) = &dateannotation($baselanguage);
    7994    my ($base2) = &dateannotation($baselanguage."2");
    8095    $base = &combine_hashes($base,$base2);
    81 
     96   
    8297    # language macro-filename and database-filename
    8398    my $macrofile = $macrodir.$file.".dm";
     
    89104             "home", "homehelp", "extlink", "authen", "collector", "docs", "usersedituser",
    90105             "usersdeleteuser", "bsummary", "status", "users", "gsdl", "userschangepasswd",
    91              "userschangepasswdok");
     106             "userschangepasswdok", "translang");
    92107
    93108    open MCROFILE, ">$macrofile" or die "MURGH\n";
     
    120135    close LANGFILE;
    121136    }
     137
    122138   
    123139    # if it doesn't have a database file then create one afresh
     
    125141    $macrofile = $macrodir.$file."2.dm";
    126142    my ($langhash2) = &parse_macrofile($macrofile);
    127     $langhash = &combine_hashes($langhash, $langhash2);
    128 
     143     
    129144    &file_to_db($file, $langhash);
    130    
     145    &file_to_db($file."2", $langhash2);
     146
    131147    my $foreign = &dateannotation($file);
    132148    my $foreign2 = &dateannotation($file . "2");
    133149    $foreign = &combine_hashes($foreign, $foreign2);
    134 
     150   
    135151    #finds the differences between the english database (base language)
    136152    #and the supplied languages database and hashes these differences
    137153    #in the form macroname{macrotext}
    138154    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
    148172
    149173sub combine_hashes {
     
    152176    my %combined = ();
    153177
    154     foreach $key (keys %$hash1) {
     178    foreach $key (sort (keys %$hash1)) {
    155179    $combined{$key} = $hash1->{$key};
    156180    }
    157     foreach $key (keys %$hash2) {
     181    foreach $key (sort (keys %$hash2)) {
    158182    $combined{$key} = $hash2->{$key};
     183    }
     184
     185    return (\%combined);
     186
     187}
     188
     189sub 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"];
    159199    }
    160200
     
    201241        $macrotext .= $_;
    202242        #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);
    203245        $macros{$key} = $macrotext;
     246
     247        #print STDERR "MACROTEXT $macrotext\n" if ($filename =~ m/french/);
    204248    }
    205249    #line in format ## "sometext" ## macro ## macroname ##
     
    207251        my $macroname = $_;
    208252        #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";
    210254               
    211255        unless ($macroname =~ m/^\#\# .*\#\#/) {
     
    232276        }
    233277
     278        #$macrotext =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg;
     279        #&unicode::ascii2utf8($macrotext);
    234280        $macros{$key} = $macrotext;
    235281    }
     
    237283    }   
    238284    close IN;
     285
    239286   
    240287    return (\%macros);
     
    248295    $file = qx/cd $ENV{'GSDLHOME'}\/macros;cvs annotate $language.dm/;
    249296    @file = split(/\n/,$file);
     297    $file = "";
    250298   
    251299    for ($p = 0; $p < scalar(@file); $p++) {
     
    259307   
    260308    if ($line =~ m/\#\# .*/) {
    261                
     309       
    262310        unless ($line =~ m/\A\#\# .*\#\#/) {
    263311        $line = $file[++$p];
     
    281329        $macrodated{$line} = $date;
    282330    }
     331   
     332       
    283333    }
    284334   
     
    295345# has been made generic so that other database files can be
    296346# updated if the need arises in the future.
     347
    297348sub file_to_db
    298349{
     
    307358    tie(%dbhash, 'GDBM_File', $database, 1, 0640) or die "$!";
    308359
    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       
    310376        if (!($dbhash{$filekey})) {
    311377        $dbhash{$filekey} = $filehash->{$filekey};
     
    324390        }
    325391    }
     392   
    326393    }
    327394    else { # create the database file for the particular language file...
     
    361428    tie(%db2hash, "GDBM_File", $db_two, GDBM_READER, 0640);
    362429
     430   
    363431    #the key is the name of the macro
    364     foreach $key (sort(keys(%db1hash))) {
     432    foreach $key (sort keys(%db1hash)) {
     433
    365434    #if the macro isn't there at all, then it's different
    366435    if (!$db2hash{$key}) {
    367         $diffhash{$key} = [$db1hash{$key},"",""];
     436        $diffhash{$key} = [$db1hash{$key}, "", ""];
    368437    }
    369438    #else if the macro is in both, want to compare date stamps of date hashes HERE
    370439    #and if foreign date is older than base date want to add to diffhash aswell
    371440    else {
     441        #print STDERR "$db_one $db_two DATE $key\n";
    372442        $macro = $key;
    373443        $macro =~ s/\A.*:://;
    374444        $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,""];
    400495            }
    401             print STDERR "NOTFOUND $macro\n" if ($found);
    402            
    403             $diffhash{$key} = [$db1hash{$key}, $foreigntext,""];
    404496            }
    405497        }
    406498        }
    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    }
    410520    untie %db1hash;
    411521    untie %db2hash;
    412522
    413523    return \%diffhash;   
    414 }
     524} 
    415525
    416526
     
    449559
    450560    # 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";
    452565    #in the hash of HTML pages, add this key to the current page and initialise it
    453566    #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]];
    455571    $keysperpage++;
    456572   
     
    458574    $limit = 7 if(!($key =~ m/_.*\_/g));
    459575    $limit = 7 if($key =~ m/help::_text.*/);
     576    $limit = 1 if($key =~ m/translang::_textinitial_/);
    460577    $limit = 3 if($key =~ m/home::.*/);
    461578    $limit = 3 if($key =~ m/gsdl::.*/);
    462579    $limit = 1 if($key =~ m/help::_(.*)texthelp.*/);
    463580    $limit = $keysperpage if ($limit <= $keysperpage);
     581
     582    #print STDERR "$key $limit $keysperpage\n";
    464583
    465584    #if have enough keys to generate a page with
     
    501620    #write thankyou page for language translator once translation is complete
    502621    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";
    504623    close THANKYOU;
    505624
     
    518637    my $keynamecount = 1;
    519638
    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
    537648    # whole lot of formatting on strings
    538649    # escape all the '_' with '\' so that Greenstone doesn't substitute
     
    547658    #$date = $&;
    548659   
    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
    553661    $text =~ s/(\<br\>\#\#.*\#\#\s*\<br\>).*/$1/g;
    554662   
     
    565673    $keynamecount = 1;
    566674   
    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    }
    570721
    571722        # so that when it is an image only get the text to translate not coding stuff aswell
    572723    if ($text =~ m/\#\# (^|.)*/) {
    573724        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>",
    575732               $query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$`"));
    576733        $keynamecount++;
    577734        print $fh ($query->textfield(-name=>"$keyname" . "$keynamecount",
    578735                         -default=>"$default",
    579                          -size=>50));
     736                         -size=>60));
    580737        $keynamecount++;
    581738        print $fh ($query->hidden(-name=>"$keyname" . "$keynamecount",-default=>"$'"),
     
    590747        my $words = scalar(@words);
    591748        my $rows = sprintf("%.0f", $words/5);
    592         print $fh ("<tr><td> $updated $text </td><td>\n");
     749        print $fh ("<tr><td>");
    593750        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",
    595758                        -rows=>$rows * 2,
    596759                        -default=>"$default",
     
    599762        }
    600763        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",
    602770                         -default=>"$default",
    603771                         -size=>50),
     
    607775    }
    608776    #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");
    616780
    617781    # adds the CGI area just written to the array of CGI areas
  • trunk/gsdl/src/recpt/langaction.cpp

    r3638 r3715  
    3131#include "gsdlunicode.h"
    3232#include "langdb.h"
     33#include "receptionist.h"
    3334#include "errno.h"
    3435#include <sys/utsname.h>
    35 
    3636 
    3737/*====================*
     
    4949 *========================*/
    5050
     51void 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}
    51100// gets the list of packages/files that contain the content of the web-forms
    52101text_tarray get_pagenos(text_t dir, ostream &logout)
     
    98147}
    99148
     149
     150// set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
     151// reponse contains 1 metadata field (Title)
     152
    100153bool langaction::init (ostream & /*logout*/) {
    101154
     
    176229void langaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
    177230                   response_t &response,text_t &response_data,
    178                    ostream &/*logout*/) {
     231                   ostream & logout) {
    179232  response = content;
    180233  response_data = "text/html";
     
    183236void langaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
    184237                     recptprotolistclass *protos, ostream &logout) {
     238 
    185239  text_t text = "";
    186240  text_t cmd = "";
     
    190244  text_t pageno ="";
    191245  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  }
    192300
    193301  // argument for page is of the form 'macrofile_pageno' so
     
    199307  if (splitarray.size() > 1)
    200308    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") {
    203330    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()) {
    206342    pageno = "picklanguage";
    207 
    208   //produce the picklanguage webpage
    209   if (pageno == "picklanguage") {
     343    logout << "@ the 1st pg\n";
    210344    cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "picklanguage.pl");
     345    logout << cmd.getcstr() << " PICKLANGUAGE\n" <<endl;
    211346    if(gsdl_system(cmd,true,logout) != 0)
    212347      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   
    214350    return;
    215351  }
    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
    264353  //if no more pages will set pageno to thankyou script
    265354  pagenos = get_pagenos(dir,logout);
    266   if (pagenos.empty())
     355 
     356  if (pagenos.empty() && pageno == "")
    267357    pageno = "thankyou";
    268  
    269 
     358 
    270359  text_t &submitargs = args[pageno];
    271   text_t submit = "SUBMIT TRANSLATION >>";
     360  text_t submit = "SUBMIT TRANSLATION";
    272361 
    273362  //if the SUBMIT TRANSLATION >> button has been pushed
     
    286375     page_itr != pagenos.end();
    287376     page_itr++) {
    288      
     377      logout << pageno.getcstr() << " page number before" <<endl;
     378 
    289379      if (*page_itr == pageno) {
    290380    page_itr++;
     
    296386    break; 
    297387      }
     388
     389      logout << pageno.getcstr() << " page number after" <<endl;
    298390    }
    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);
    304397}
    305398
    306399void langaction::define_webpage (displayclass &disp,
    307400                 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) {
    310403 
    311404  // produces HTML page with the current pages contents
     
    324417 
    325418  /* ============================ START WEB-FORM HTML CODE ============================ */
     419  text += "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>";
     420
    326421  text += "\n<input type=hidden name=\"a\" value=\"lang\">";
    327422  text += "\n<input type=hidden name=\"p\" value=\"translang_";
     
    329424  text += "\">\n";
    330425
    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
    336428 
    337429  //if not a special case page display translation info
    338430  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_ ";
    340435    text += pageno;
    341     text += " of ";
     436    text += " _textof_ ";
    342437    text += pagenos.size();
    343     text += " in to ";
    344     text += lang;
    345438    text += "</strong></center><p><p>\n";
    346439  }
    347440 
     441  utf8outconvertclass text_tutf8;
     442
    348443  //read in HTML from file
    349444  while(readfile.getline(temp, BUFFSIZE-1)) {
    350445    text_t t_temp = temp;
    351446    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;
    352469    text += "\n";
    353470  }
     
    356473  //if not a special case page display translation info
    357474  if ((pageno != "thankyou") && (pageno != "picklanguage")) {
    358     text += "<center><strong>You are currently translating page ";
     475    text += "<center><strong> _textcurrpage_ ";
    359476    text += pageno;
    360     text += " of ";
     477    text += " _textof_ ";
    361478    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();
    365547  }
    366  
    367  
    368548  /* ============================ END WEB-FORM HTML CODE ============================ */
     549 
    369550 
    370551  // THE FOLLOWING MACROS ARE DEFINED IN translang.dm MACRO FILE
     
    375556  //  disp.setmacro("formaction", "translang", "/cgi-bin/dg5/library");
    376557  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);
    377567
    378568}
     
    388578      << ("_" + arg_p + ":footer_\n");
    389579
     580  logout << outconvert << disp << ("_" + arg_p + ":header_\n");
     581
    390582  return true;
    391583}
    392584
    393585
    394 
    395 
  • trunk/gsdl/src/recpt/langaction.h

    r3632 r3715  
    6565  void define_webpage (displayclass &disp,
    6666               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);
    6969   
    70 
     70 
    7171};
    7272
Note: See TracChangeset for help on using the changeset viewer.