Changeset 4125


Ignore:
Timestamp:
2003-04-11T10:20:42+12:00 (21 years ago)
Author:
mdewsnip
Message:

Some small improvements.

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

Legend:

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

    r4118 r4125  
    4343sub main
    4444{
    45     # directory in which to put the generated html pages
    46     my $lang_dir = util::filename_cat($ENV{'GSDLHOME'},"tmp","lang");
    47     my @lang_list;
    48     my $langlog_fname = util::filename_cat($lang_dir,"languages.log");
     45    my $gsdldir = "$ENV{'GSDLHOME'}";
    4946
    50     if (!-e $langlog_fname) {
    51     # generate one based on content of etc/main.cfg
    52     my $maincfg_fname = util::filename_cat($ENV{'GSDLHOME'},"etc","main.cfg");
     47    # Read the languages available from etc/main.cfg
     48    my $maincfg_fname = util::filename_cat($gsdldir, "etc", "main.cfg");
     49    open(MCFILE, "<$maincfg_fname") or die "Error: Could not open $maincfg_fname: $!\n";
    5350
    54     open(MCFILE, "<$maincfg_fname")
    55         || die "Unable to open $maincfg_fname: $!\n";
    56     my $line;
    57     while (defined ($line=<MCFILE>)) {
    58         chomp($line);
    59         if ($line =~ m/^Language\s+/i) {
    60         my @args = split(/ +/,$line);
    61         my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
    62         my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
    63         push(@lang_list, { 'long' => $lang_long, 'abbr' => $lang_abbr } );
    64         }
     51    my @languages;
     52    my $line;
     53    while (defined ($line=<MCFILE>)) {
     54    chomp($line);
     55    if ($line =~ m/^Language\s+/i) {
     56        my @args = split(/ +/,$line);
     57        my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
     58        my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
     59        push(@languages, $lang_long);
    6560    }
    66     close MCFILE;
     61    }
     62    close MCFILE;
    6763
    68     open(LANGFILE,">$langlog_fname")
    69         || die "Unable to create $langlog_fname: $!\n";
     64    # Write the HTML content of the page to tmp/lang/picklanguage.lang
     65    my $picklang_fname = util::filename_cat($gsdldir, "tmp", "lang", "picklanguage.lang");
    7066
    71     my $l;
    72     my $first = 1;
    73     foreach $l ( @lang_list ) {
    74         my $long = lc($l->{'long'});
    75         my $abbr = $l->{'abbr'};
    76         if ($first =~ 1) {
    77         print LANGFILE "$long\n$abbr";
    78         $first = 0;
    79         }
    80         else {
    81         print LANGFILE "\n$long\n$abbr";
    82         }
    83     }
    84     close LANGFILE;
     67    # Make the file world writeable
     68    my $currentmask = umask;
     69    umask(0000);
     70    if (! open(HTMLFILE,">$picklang_fname")) {
     71    umask($currentmask);
     72    die "Error: Could not create $picklang_fname: $!\n";
    8573    }
     74    umask($currentmask);
    8675
    87     open(LANGFILE, "<$langlog_fname")
    88     || die "Unable to open $langlog_fname for reading: $!\n";
    89 
    90     #reads into the languages array all languages currently in use
    91     #and their corresponding language codes from the languages.log file
    92     my @languages;
    93     while (<LANGFILE>) {
    94     $lang = $_;
    95     chomp($lang);
    96     push(@languages,$lang);
    97     <LANGFILE>;
    98     }
    99     close LANGFILE;
    100 
    101     #opens a file to write HTML content of the page to
    102     my $picklang_fname = util::filename_cat($lang_dir, "picklanguage.lang");
    103     open(HTMLFILE, ">$picklang_fname")
    104     || die "Unable to open $picklang_fname: $!\n";
    105 
    106     #writes to file the instructions on how to use the interface (_textinitial)
    107     #and then displays a table at the end with menu options from which the user
    108     #selects their base and translation languages, and submits these choices
    109     #to proceed into the interface translation agency
     76    # Writes to file the instructions on how to use the interface (_textinitial_)
     77    #   and then displays a table at the end with menu options from which the user
     78    #   selects their base and translation languages, and submits these choices
     79    #   to proceed into the interface translation agency
    11080    my $query = new CGI;
    11181    print HTMLFILE (" _textinitial_ <br>\n",
     
    11484            $query->popup_menu(-name=>"bl",
    11585                       -values=>\@languages,
    116                        -default=>'english'),
     86                       -default=>'English'),
    11787            "<p></center></td><td><center>\n",
    11888            "_textselectforeign_ <p>\n",
     
    12898            "</center><p>\n",
    12999            "<center><img src=\"_httpimg_/divb.gif\"></center><p>");
    130    
    131100    close HTMLFILE;
    132101}
  • trunk/gsdl/bin/script/submit_translation.pl

    r4118 r4125  
    6868    $sourcelang =~ tr/A-Z/a-z/;
    6969    $targetlang =~ tr/A-Z/a-z/;
    70 
    71     # Handles cases where the macro file name is different to the language name
    72     $sourcelang = "port" if ($sourcelang =~ m/portuguese/);
    73     $sourcelang = "indo" if ($sourcelang =~ m/indonesian/);
    74     $targetlang = "port" if ($targetlang =~ m/portuguese/);
    75     $targetlang = "indo" if ($targetlang =~ m/indonesian/);
    7670
    7771    my $gsdldir = "$ENV{'GSDLHOME'}/";
     
    186180    $macrotext = "[l=$targetcode] {" . $macrotext . "}\n";
    187181
    188     my $targetkey = &get_target_key_equivalent($sourcelang, $targetlang, $sourcekey);
     182    my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey);
    189183    $translations{$targetkey} = $macrotext;
    190184    }
     
    194188
    195189
    196 sub get_target_key_equivalent
    197 {
    198     my ($sourcelang, $targetlang, $sourcekey) = @_;
    199 
    200     my $macrofile = $sourcekey;
     190sub get_macrofile_name
     191{
     192    my ($language, $suffix) = @_;
     193
     194    my $macrofilename = $language;
     195
     196    # Handles cases where the macro file name is different to the language name
     197    $macrofilename = "port" if ($language =~ m/portuguese/);
     198    $macrofilename = "indo" if ($language =~ m/indonesian/);
     199
     200    # Add suffix (if any) and file extension, and return
     201    $macrofilename = $macrofilename . $suffix . ".dm";
     202    return $macrofilename;
     203}
     204
     205
     206sub get_macroname_equivalent
     207{
     208    my ($languageA, $languageB, $languageAkey) = @_;
     209
     210    my $macrofile = $languageAkey;
    201211    $macrofile =~ s/^([^:]+)::(.*)/$1/;
    202     my $key = $sourcekey;
     212    my $key = $languageAkey;
    203213    $key =~ s/^([^:])+::(.*)/$2/;
    204214
    205     my $targetkey;
    206     if ($macrofile eq ($sourcelang . ".dm")) {
    207     $targetkey = $targetlang . ".dm" . "::" . $key;
    208     }
    209     if ($macrofile eq ($sourcelang . "2.dm")) {
    210     $targetkey = $targetlang . "2.dm" . "::" . $key;
    211     }
    212 
    213     return ($targetkey);
     215    my $languageBkey;
     216    if ($macrofile eq &get_macrofile_name($languageA, "")) {
     217    $languageBkey = &get_macrofile_name($languageB, "") . "::" . $key;
     218    }
     219    if ($macrofile eq &get_macrofile_name($languageA, "2")) {
     220    $languageBkey = &get_macrofile_name($languageB, "2") . "::" . $key;
     221    }
     222
     223    return ($languageBkey);
    214224}
    215225
     
    246256    my ($sourcelang, $targetlang, $macrosdir) = @_;
    247257
    248     my $targetdmfile1 = $macrosdir . $targetlang . ".dm";
    249     my $targetdmfile2 = $macrosdir . $targetlang . "2.dm";
     258    my $targetdmfile1 = $macrosdir . &get_macrofile_name($targetlang, "");
     259    my $targetdmfile2 = $macrosdir . &get_macrofile_name($targetlang, "2");
    250260
    251261    my $currentfile = "1";
     
    262272
    263273    # Check if this is a target macro
    264     if ($macrofile eq ($targetlang . ".dm") || $macrofile eq ($targetlang . "2.dm")) {
    265         if ($macrofile eq ($targetlang . "2.dm") && $currentfile eq "1") {
     274    if ($macrofile eq &get_macrofile_name($targetlang, "") ||
     275        $macrofile eq &get_macrofile_name($targetlang, "2")) {
     276
     277        # Detect the point where we start on the auxiliary macros
     278        if ($macrofile eq &get_macrofile_name($targetlang, "2") && $currentfile eq "1") {
    266279        # Write the macros for the package just finished
    267280        &write_macros(TARGET_DM_FILE, $currentpackage, $textmacros, $iconmacros);
  • trunk/gsdl/bin/script/translator.pl

    r4118 r4125  
    3434
    3535
     36use util;
    3637use GDBM_File;
    3738use CGI;
     
    6667    # If the source language is not English, it may not be up to date
    6768    if ($sourcelang !~ m/english/) {
    68     # print STDERR "Warning: Source language is not English. You should check that" .
    69     #              " the source language is up to date before beginning.\n";
    70     }
    71 
    72     # Handles cases where the macro file name is different to the language name
    73     $sourcelang = "port" if ($sourcelang =~ m/portuguese/);
    74     $sourcelang = "indo" if ($sourcelang =~ m/indonesian/);
    75     $targetlang = "port" if ($targetlang =~ m/portuguese/);
    76     $targetlang = "indo" if ($targetlang =~ m/indonesian/);
    77 
    78     my $gsdldir = "$ENV{'GSDLHOME'}/";
    79     my $macrosdir = $gsdldir . "macros/";
     69    print STDERR "Warning: Source language is not English. You should check that" .
     70                 " the source language is up to date before beginning.\n";
     71    }
     72
     73    my $gsdldir = "$ENV{'GSDLHOME'}";
     74    my $macrosdir = util::filename_cat($gsdldir, "macros");
    8075
    8176    # Check that the source language macro files exist, and parse them
    82     my $sourcedmfile1 = $sourcelang . ".dm";
    83     my $sourcehash1;
    84     if (-e $macrosdir.$sourcedmfile1) {
    85     $sourcehash1 = &parse_macrofile($macrosdir, $sourcedmfile1);
    86     }
    87 
    88     my $sourcedmfile2 = $sourcelang . "2.dm";
    89     my $sourcehash2;
    90     if (-e $macrosdir.$sourcedmfile2) {
    91     $sourcehash2 = &parse_macrofile($macrosdir, $sourcedmfile2);
    92     }
     77    my $sourcedmname1 = &get_macrofile_name($sourcelang, "");
     78    my $sourcehash1 = &parse_macrofile($macrosdir, $sourcedmname1);
     79    my $sourcedmname2 = &get_macrofile_name($sourcelang, "2");
     80    my $sourcehash2 = &parse_macrofile($macrosdir, $sourcedmname2);
    9381
    9482    # Make sure some macros exist to be translated
     
    9987    # Combine the two source hashes
    10088    my $sourcehash = &combine_hashes($sourcehash1, $sourcehash2);
    101     # print "Source hash:\n";
    102     # &display_hash($sourcehash);
    10389
    10490    # Check if this is a new translation process or the continuation of an old one
    105     $translationdir = $gsdldir . "tmp/lang/" . $sourcelang . "-" . $targetlang . "/";
    106     $translationdb = $translationdir . "translation.db";
    107     $updatedb = $translationdir . "update.db";
     91    $translationdir = util::filename_cat($gsdldir, "tmp", "lang", "$sourcelang-$targetlang");
     92    $translationdb = util::filename_cat($translationdir, "translation.db");
     93    $updatedb = util::filename_cat($translationdir, "update.db");
    10894
    10995    if (! -e $translationdir) {
    110     # Create a directory to store the data for the new translation
     96    # Create a directory to store the data for the new translation, make world-writeable
     97    my $currentmask = umask;
     98    umask(0000);
    11199    if (! mkdir($translationdir, 0777)) {
     100        umask($currentmask);
    112101        die "Error: Couldn't create directory $translationdir.\n";
    113102    }
     103    umask($currentmask);
    114104
    115105    # Start a new database for the translation information
     
    117107
    118108    # Work out what the target language code should be, and store it in the database
    119     my $langdir = $gsdldir . "tmp/lang/";
    120     my $langlogfile = $langdir . "languages.log";
     109    my $maincfgfile = util::filename_cat($gsdldir, "etc", "main.cfg");
    121110    my $languagecodes = &get_language_codes();
    122     my $targetcode = &get_language_code($targetlang, $langlogfile, $languagecodes);
    123     print STDERR "Target language code: $targetcode\n";
     111    my $targetcode = &get_language_code($targetlang, $maincfgfile, $languagecodes);
    124112    $translationdata{"*target_lang_code*"} = $targetcode;
    125113
     
    134122
    135123    # Create the target language macro files if they don't exist
    136     my $targetdmfile1 = $targetlang . ".dm";
    137     if (! -e $macrosdir.$targetdmfile1) {
    138     # print "Target macro file $macrosdir$targetdmfile1 does not exist... creating.\n";
    139     &create_empty_macrofile($macrosdir.$sourcedmfile1, $macrosdir.$targetdmfile1);
    140     }
    141     my $targetdmfile2 = $targetlang . "2.dm";
    142     if (! -e $macrosdir.$targetdmfile2) {
    143     # print "Target macro file $macrosdir$targetdmfile2 does not exist... creating.\n";
    144     &create_empty_macrofile($macrosdir.$sourcedmfile2, $macrosdir.$targetdmfile2);
     124    my $targetdmname1 = &get_macrofile_name($targetlang, "");
     125    my $targetdmfile1 = util::filename_cat($macrosdir, $targetdmname1);
     126    if (! -e $targetdmfile1) {
     127    my $sourcedmfile1 = util::filename_cat($macrosdir, $sourcedmname1);
     128    &create_empty_macrofile($sourcedmfile1, $targetdmfile1);
     129    }
     130    my $targetdmname2 = &get_macrofile_name($targetlang, "2");
     131    my $targetdmfile2 = util::filename_cat($macrosdir, $targetdmname2);
     132    if (! -e $targetdmfile2) {
     133    my $sourcedmfile2 = util::filename_cat($macrosdir, $sourcedmname2);
     134    &create_empty_macrofile($sourcedmfile2, $targetdmfile2);
    145135    }
    146136
    147137    # Parse the target language macro files
    148     my $targethash1 = &parse_macrofile($macrosdir, $targetdmfile1);
    149     my $targethash2 = &parse_macrofile($macrosdir, $targetdmfile2);
     138    my $targethash1 = &parse_macrofile($macrosdir, $targetdmname1);
     139    my $targethash2 = &parse_macrofile($macrosdir, $targetdmname2);
    150140
    151141    # Combine the two target hashes
    152142    my $targethash = &combine_hashes($targethash1, $targethash2);
    153     # print "Target hash:\n";
    154     # &display_hash($targethash);
    155143
    156144    # Determine the macros that need translating
    157145    my $needstranslating = &find_macros_needing_translation($sourcelang, $sourcehash,
    158146                                $targetlang, $targethash);
    159     # print "Macros needing translation:\n";
    160     # &display_hash($needstranslating);
    161147
    162148    # Generates HTML code to display user interface on webpage with what needs translation
    163     &generate_pages($sourcelang, $targetlang, $needstranslating);
     149    my $targetcode = $translationdata{"*target_lang_code*"};
     150    print STDERR "Target language code: $targetcode\n";
     151    &generate_pages($sourcelang, $targetlang, $targetcode, $needstranslating);
    164152
    165153    # Clean up
     
    169157
    170158
     159sub get_macrofile_name
     160{
     161    my ($language, $suffix) = @_;
     162
     163    my $macrofilename = $language;
     164
     165    # Handles cases where the macro file name is different to the language name
     166    $macrofilename = "port" if ($language =~ m/portuguese/);
     167    $macrofilename = "indo" if ($language =~ m/indonesian/);
     168
     169    # Add suffix (if any) and file extension, and return
     170    $macrofilename = $macrofilename . $suffix . ".dm";
     171    return $macrofilename;
     172}
     173
     174
    171175sub get_language_code
    172176{
    173     my ($language, $langlogfile, $languagecodes) = @_;
    174 
    175     # Try the languages.log file
    176     open(LANG_LOG_IN, "<$langlogfile") or die "Error: Could not open $langlogfile.\n";
    177 
    178     my $linenum = "odd";
    179     my $found = "false";
    180     while (<LANG_LOG_IN>) {
     177    my ($language, $maincfgfile, $languagecodes) = @_;
     178
     179    # Check if the language is in the main.cfg file
     180    open(MAIN_CFG_IN, "<$maincfgfile") or die "Error: Could not open $maincfgfile.\n";
     181    my $lastlangline;
     182    while (<MAIN_CFG_IN>) {
    181183    $line = $_;
    182184    chomp($line);
    183 
    184     # Check if the language code appears in the languages.log file
    185     if ($linenum eq "odd") {
    186         if ($line eq $language) {
    187         $found = "true";
     185    # print "Line: $line\n";
     186    if ($line =~ m/^Language\s+/i) {
     187        my @args = split(/ +/,$line);
     188        my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
     189        $lang_abbr =~ tr/A-Z/a-z/;
     190        my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
     191        $lang_long =~ tr/A-Z/a-z/;
     192
     193        # Is this the language we are translating into?
     194        if ($lang_long eq $language) {
     195        return $lang_abbr;
    188196        }
    189         $linenum = "even";
    190     }
    191     else {
    192         if ($found eq "true") {
    193         return $line;
    194         }
    195         $linenum = "odd";
    196     }
    197     }
    198 
    199     close LANG_LOG_IN;
     197
     198        $lastlangline = $line;
     199    }
     200    }
     201    close MAIN_CFG_IN;
    200202
    201203    # Try to find it using the ISO 639 language codes
     
    209211    }
    210212
    211     # Add the language code to the languages.log file
    212     open LANG_LOG_OUT, ">>$langlogfile" or die "Error: Could not append to $langlogfile.\n";
    213     print LANG_LOG_OUT "\n$language\n$langcode";
    214     close LANG_LOG_OUT;
     213    # Add the new language code into the main.cfg file
     214    open MAIN_CFG_OUT, ">$maincfgfile.new" or die "Error: Could not write $maincfgfile.new\n";
     215    open MAIN_CFG_IN, "<$maincfgfile" or die "Error: Could not open $maincfgfile.\n";
     216    my $inmacros = "false";
     217    while (<MAIN_CFG_IN>) {
     218    $line = $_;
     219    chomp($line);
     220    print MAIN_CFG_OUT $line;
     221    if ($line =~ m/^macrofiles /) {
     222        $inmacros = "true";
     223    }
     224    if ($inmacros eq "true" && $line !~ m/\\$/) {
     225        print MAIN_CFG_OUT " \\\n";
     226        print MAIN_CFG_OUT "                $language" . ".dm $language" . "2.dm";
     227        $inmacros = "false";
     228    }
     229    print MAIN_CFG_OUT "\n";
     230
     231    if ($line eq $lastlangline) {
     232        # Change language into title case
     233        my $langtitlecase = $language;
     234        substr($langtitlecase, 0, 1) =~ tr/a-z/A-Z/;
     235        print MAIN_CFG_OUT ("Language shortname=$langcode longname=$langtitlecase ",
     236                "default_encoding=utf-8\n");
     237    }
     238    }
     239    close MAIN_CFG_IN;
     240    close MAIN_CFG_OUT;
     241
     242    # Delete the old main.cfg and replace it with the new one
     243    unlink($maincfgfile);
     244    rename("$maincfgfile.new", $maincfgfile);
    215245
    216246    return $langcode;
     
    261291    my ($macrosdir, $macrofile) = @_;
    262292
     293    # Opens macro file or returns
     294    my $macropath = util::filename_cat($macrosdir, $macrofile);
     295    open(IN, "<$macropath") or return;
     296
    263297    # Initialises some local variables
    264298    my $currpackage;
    265299    my %macros = ();
    266 
    267     # Opens macro file or returns
    268     my $macropath = $macrosdir . $macrofile;
    269     open(IN, "<$macropath") or return;
    270300
    271301    # Reads in contents of macro file, line by line
     
    357387
    358388
    359 sub display_hash
    360 {
    361     my ($hash) = @_;
    362 
    363     foreach $key (sort (keys %$hash)) {
    364     print $key . "\n";
    365     print $hash->{$key} . "\n";
    366     }
    367 }
    368 
    369 
    370389sub find_macros_needing_translation
    371390{
     
    377396        if ($translationdata{$sourcekey} ne $sourcehash->{$sourcekey}) {
    378397        # print "Source macro $sourcekey has changed value.\n";
    379 
    380         my $targetkey = &get_target_key_equivalent($sourcelang, $targetlang,
    381                                $sourcekey);
     398        my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang,
     399                              $sourcekey);
    382400        if ($targethash->{$targetkey}) {
    383401            $updatedata{$targetkey} = $targethash->{$targetkey};
     
    409427
    410428    # Macros that need translating are those that are in the source language macro file
    411     #  but no translation exists in the translation database
     429    #  but no translation exists in the translation database...
    412430    foreach $sourcekey (sort keys(%$sourcehash)) {
    413     my $targetkey = &get_target_key_equivalent($sourcelang, $targetlang, $sourcekey);
     431    my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey);
    414432    if (!$translationdata{$targetkey}) {
    415433        # print "Macro $sourcekey needs translating.\n";
     
    421439    # ...and those in the list of macros to update
    422440    foreach $targetkey (sort keys(%updatedata)) {
    423     my $sourcekey = &get_source_key_equivalent($sourcelang, $targetlang, $targetkey);
     441    my $sourcekey = &get_macroname_equivalent($targetlang, $sourcelang, $targetkey);
    424442    $needstranslating{$sourcekey}[0] = $sourcehash->{$sourcekey};
    425443    $needstranslating{$sourcekey}[1] = $updatedata{$targetkey};
     
    430448
    431449
    432 sub get_source_key_equivalent
    433 {
    434     my ($sourcelang, $targetlang, $targetkey) = @_;
    435 
    436     my $macrofile = $targetkey;
     450sub get_macroname_equivalent
     451{
     452    my ($languageA, $languageB, $languageAkey) = @_;
     453
     454    my $macrofile = $languageAkey;
    437455    $macrofile =~ s/^([^:]+)::(.*)/$1/;
    438     my $key = $targetkey;
     456    my $key = $languageAkey;
    439457    $key =~ s/^([^:])+::(.*)/$2/;
    440458
    441     my $sourcekey;
    442     if ($macrofile eq ($targetlang . ".dm")) {
    443     $sourcekey = $sourcelang . ".dm" . "::" . $key;
    444     }
    445     if ($macrofile eq ($targetlang . "2.dm")) {
    446     $sourcekey = $sourcelang . "2.dm" . "::" . $key;
    447     }
    448 
    449     return ($sourcekey);
    450 }
    451 
    452 
    453 sub get_target_key_equivalent
    454 {
    455     my ($sourcelang, $targetlang, $sourcekey) = @_;
    456 
    457     my $macrofile = $sourcekey;
    458     $macrofile =~ s/^([^:]+)::(.*)/$1/;
    459     my $key = $sourcekey;
    460     $key =~ s/^([^:])+::(.*)/$2/;
    461 
    462     my $targetkey;
    463     if ($macrofile eq ($sourcelang . ".dm")) {
    464     $targetkey = $targetlang . ".dm" . "::" . $key;
    465     }
    466     if ($macrofile eq ($sourcelang . "2.dm")) {
    467     $targetkey = $targetlang . "2.dm" . "::" . $key;
    468     }
    469 
    470     return ($targetkey);
     459    my $languageBkey;
     460    if ($macrofile eq &get_macrofile_name($languageA, "")) {
     461    $languageBkey = &get_macrofile_name($languageB, "") . "::" . $key;
     462    }
     463    if ($macrofile eq &get_macrofile_name($languageA, "2")) {
     464    $languageBkey = &get_macrofile_name($languageB, "2") . "::" . $key;
     465    }
     466
     467    return ($languageBkey);
    471468}
    472469
     
    476473sub generate_pages
    477474{
    478     my ($sourcelang, $targetlang, $needstranslating) = @_;
     475    my ($sourcelang, $targetlang, $targetcode, $needstranslating) = @_;
    479476
    480477    my %pagehash = ();
    481478
    482     @pageno = ();
     479    @pages = ();
    483480    $pageno = 1;
    484481    $keysperpage = 0;
     
    493490    #each macro is associated with some macrotext and whether it was from the core
    494491    #or auxiliary macrofile
    495     # my $targetkey = &get_target_key_equivalent($sourcelang, $targetlang, $sourcekey);
    496     # print "Source key: $sourcekey Target key: $targetkey\n";
    497 
    498492    $pagehash->{$pageno}->{$sourcekey} = $needstranslating->{$sourcekey};
    499493    $keysperpage++;
    500494
    501     #reduce the number of macros per page in these cases
    502     # $limit = 7 if($key =~ m/collector::_text.*/);
    503     # $limit = 7 if($key =~ m/help::_text.*/);
    504     # $limit = 1 if($key =~ m/translang::_textinitial_/);
    505     # $limit = 3 if($key =~ m/home::.*/);
    506     # $limit = 3 if($key =~ m/gsdl::.*/);
    507     # $limit = 1 if($key =~ m/help::_(.*)texthelp.*/);
    508     # $limit = $keysperpage if ($limit <= $keysperpage);
    509 
    510     #if have enough keys to generate a page with
     495    # If have enough keys to generate a page with
    511496    if ($keysperpage == $limit) {
    512497        #opens a file to write the HTML code to for current page
    513         open HTMLFILE, ">$translationdir/$pageno.lang";
     498        my $transpagefile = util::filename_cat($translationdir, $pageno . ".lang");
     499        open HTMLFILE, ">$transpagefile";
    514500
    515501        #passes hash of keys for current page and filehandle, returns CGI data
    516         &generate_form($sourcelang, $targetlang, $pagehash->{$pageno}, \*HTMLFILE);
     502        &generate_form($sourcelang, $targetlang, $targetcode,
     503               $pagehash->{$pageno}, \*HTMLFILE);
    517504        close HTMLFILE;
    518505
    519506        #push the page number onto the array of pages
    520         push(@pageno, $pageno);
     507        push(@pages, $pageno);
    521508        $pageno++;
    522509
     
    530517    if ($keysperpage != 0) {
    531518    # writes out the remaining keys, same format as above
    532     open HTMLFILE, ">$translationdir/$pageno.lang";
    533     &generate_form($sourcelang, $targetlang, $pagehash->{$pageno}, \*HTMLFILE);
     519    my $transpagefile = util::filename_cat($translationdir, $pageno . ".lang");
     520    open HTMLFILE, ">$transpagefile";
     521    &generate_form($sourcelang, $targetlang, $targetcode, $pagehash->{$pageno}, \*HTMLFILE);
    534522    close HTMLFILE;
    535     push(@pageno, $pageno);
    536     }
    537 
    538     #writes each page number to a file
    539     open PAGELOG, ">$translationdir/pageno.log";
    540     foreach $page (@pageno) {
    541     print PAGELOG $page, "\n";
    542     }
    543     close PAGELOG;
    544 
    545     #write thankyou page for language translator once translation is complete
    546     open THANKYOU, ">$translationdir/thankyou.lang" or die("MURGH\n");
     523    push(@pages, $pageno);
     524    }
     525
     526    # Write the number of pages to a file
     527    my $numpagesfile = util::filename_cat($translationdir, "numpages.log");
     528    open NUMPAGESLOG, ">$numpagesfile" or die "Error: Could not write $numpagesfile.\n";
     529    print NUMPAGESLOG ($pageno - 1);
     530    close NUMPAGESLOG;
     531
     532    # Write thankyou page for language translator once translation is complete
     533    my $thankyoufile = util::filename_cat($translationdir, "thankyou.lang");
     534    open THANKYOU, ">$thankyoufile" or die "Error: Could not write $thankyoufile.\n";
    547535    print THANKYOU ("<center> _textthanks_ $targetlang _texttrans_ _textgetdmfiles_ ",
    548536            "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>",
     
    551539            "<p></center>\n");
    552540    close THANKYOU;
    553 
    554     #returns CGI data
    555     return @queries;
    556541}
    557542
     
    561546    my $sourcelang = shift(@_);
    562547    my $targetlang = shift(@_);
     548    my $targetcode = shift(@_);
    563549    my $formhash = shift(@_);
    564550    my $fh = shift(@_);
     
    569555
    570556    $first = "true";
    571 
    572557    foreach $key (sort (keys(%$formhash))) {
    573558
     
    734719           $query->submit($pageno, "_textsubmit_"),
    735720           "</td></tr><tr><td width=\"50%\"></td><td align=right width=\"50%\">",
    736            "<br> _textsubmittext_ \n",
    737            "_textgetdmfiles_ ",
    738            "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>",
    739            " &amp; ",
    740            "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.",
     721           "<br> _textsubmittext_ ",
     722           "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.",
     723           # "_textgetdmfiles_ ",
     724           # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>",
     725           # " &amp; ",
     726           # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.",
    741727           "</td></tr></table>");
    742 
    743     # adds the CGI area just written to the array of CGI areas
    744     push (@queries, $query);
    745 
    746     # return $query;
    747728}
    748729
     
    776757    if ($macrofile eq ($sourcelang . "2.dm")) {
    777758    return "2";  # Auxiliary macro
     759    }
     760}
     761
     762
     763sub display_hash
     764{
     765    my ($hash) = @_;
     766
     767    foreach $key (sort (keys %$hash)) {
     768    print $key . "\n";
     769    print $hash->{$key} . "\n";
    778770    }
    779771}
Note: See TracChangeset for help on using the changeset viewer.