Changeset 4129


Ignore:
Timestamp:
2003-04-11T16:41:30+12:00 (21 years ago)
Author:
mdewsnip
Message:

Much better support for icon macros.

Location:
trunk/gsdl/bin/script
Files:
2 edited

Legend:

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

    r4125 r4129  
    3838
    3939
     40use util;
    4041use GDBM_File;
    4142
     
    6970    $targetlang =~ tr/A-Z/a-z/;
    7071
    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");
    7577
    7678    # Open the two database files for the translation
     
    7981
    8082    # 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));
    8386    # print "Submissions:\n";
    8487    # &display_hash($submissions);
     
    8891
    8992    # Writes the target macro files
    90     my $macrosdir = $gsdldir . "macros/";
     93    my $macrosdir = util::filename_cat($gsdldir, "macros");
    9194    &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";
    92115
    93116    # Clean up
     
    99122sub parse_user_submission
    100123{
    101     my ($sourcelang, $targetlang, $filename) = @_;
     124    my ($sourcelang, $targetlang, $targetcode, $filename) = @_;
    102125
    103126    #opens the args file or kills program
     
    106129    #stores a hash of macronames with numbers still appended and their values
    107130    my %distinctkeys = ();
     131    my %icontextvals = ();
    108132
    109133    #while there are still lines left to read
     
    120144    # print "Line: $line\n";
    121145
     146    # Does the line contain a new CGI argument?
    122147    if ($line =~ m/^ \"/) {
    123         #if the line contains :: (browser converts to %3A%3A) then it has a macroname
     148        # If the line contains :: (browser converts to %3A%3A) then it has a macroname
    124149        if ($line =~ m/%3A%3A/) {
    125150        #hashes the previous macro and its value, provided the value is non-empty
    126151        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            }
    128159        }
    129160
     
    149180        #hashes the previous macro and its value, provided the value is non-empty
    150181        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            }
    152189        }
    153190        $macroname = "";
     
    155192        }
    156193    }
     194    # No, so check if it is part of a multi-line macro
    157195    else {
    158         # Check if this is part of a multi-line macro
    159196        if ($macroname ne "") {
    160197        $extravalue = $line;
     
    174211    # Create a hash map containing the translations to add
    175212    my %translations = ();
    176     my $targetcode = $translationdata{"*target_lang_code*"};
    177213
    178214    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    }
    181233
    182234    my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey);
     
    256308    my ($sourcelang, $targetlang, $macrosdir) = @_;
    257309
    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"));
    260312
    261313    my $currentfile = "1";
  • trunk/gsdl/bin/script/translator.pl

    r4125 r4129  
    331331    }
    332332
    333     # Line in format ## "sometext" ## macro ## macroname ##
     333    # Icon: line in format ## "sometext" ## macro ## macroname ##
    334334    elsif (/^\#\# .*/) {
    335335        my $macroname = $_;
     
    360360        # key to the hash and the database
    361361        my $key = $macrofile . "::" . $currpackage . "::" . $macroname;
     362        # print "Icon, key: $key\n text: $macrotext\n";
    362363        # hashes macroname and macrotext
    363364        $macros{$key} = $macrotext;
     
    432433    if (!$translationdata{$targetkey}) {
    433434        # print "Macro $sourcekey needs translating.\n";
     435        # print "Text to translate: $sourcehash->{$sourcekey}\n";
    434436        $needstranslating{$sourcekey}[0] = $sourcehash->{$sourcekey};
    435437        $needstranslating{$sourcekey}[1] = "";
     
    524526    }
    525527
    526     # Write the number of pages to a file
     528    # Write the number of pages to a file for use by the receptionist
    527529    my $numpagesfile = util::filename_cat($translationdir, "numpages.log");
    528530    open NUMPAGESLOG, ">$numpagesfile" or die "Error: Could not write $numpagesfile.\n";
     
    533535    my $thankyoufile = util::filename_cat($translationdir, "thankyou.lang");
    534536    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             " &amp; ",
    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            # " &amp; ",
     543            # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.",
    539544            "<p></center>\n");
    540545    close THANKYOU;
     
    583588    $default =~ s/(\A\n)//;
    584589    $default =~ s/(\n\Z)//;
    585     # print "Key: $keyname Text: $text Default: $default\n";
    586 
    587     $keynamecount = 1;
    588    
     590
     591    # $keynamecount = 1;
     592
    589593    #tells whether is a core or auxiliary macro
    590594    my $priority = &core_or_auxiliary_macro($sourcelang, $keyname);
     
    627631        # so that when it is an image only get the text to translate not coding stuff aswell
    628632    if ($text =~ m/\#\# (^|.)*/) {
     633        # print STDERR "\nIcon -- Key: $keyname\nText: $text\n"; # Default: $default\n";
    629634        if ($& =~ m/".*"/) {
    630635        #prints to the file two text fields, the left one contains the base language
    631636        #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;
    632646
    633647        my $textbox1;
    634648        if (1) {
    635             $rows = 1;  # if ($rows < 1);
    636649            $textbox1 = "<textarea name=\"whocaresh\" rows=\"$rows\" cols=\"50\" readonly=\"1\">";
    637             $textbox1 .= "$& </textarea>\n";
     650            $textbox1 .= "$icontext</textarea>\n";
    638651        }
    639652        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);
    644655        }
    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++;
    650659
    651660        my $textbox2;
    652661        if (1) {
    653             $textbox2 = "<textarea name=\"$keyname$keynamecount\" rows=\"$rows\" cols=\"50\">";
     662            $textbox2 = "<textarea name=\"$keyname\" rows=\"$rows\" cols=\"50\">";
    654663            $textbox2 .= "$default</textarea><br>\n";
    655664        }
    656665        else {
    657             $textbox2 = $query->textfield(-name=>"$keyname" . "$keynamecount",
    658                           -default=>"$default",
     666            $textbox2 = $query->textfield(-name=>"$keyname", -default=>"$default",
    659667                          -size=>50);
    660668        }
    661669        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");
    665678        }
    666679    }
     680    # Text macro
    667681    elsif ($text =~ m/\S+/) {
    668682        $text =~ s/\s+/ /g;
     
    719733           $query->submit($pageno, "_textsubmit_"),
    720734           "</td></tr><tr><td width=\"50%\"></td><td align=right width=\"50%\">",
    721            "<br> _textsubmittext_ ",
     735           "<br> _textsubmittext_ <br> _textviewtranslation_ ",
    722736           "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.",
    723737           # "_textgetdmfiles_ ",
Note: See TracChangeset for help on using the changeset viewer.