Changeset 13693


Ignore:
Timestamp:
2007-01-19T14:20:58+13:00 (17 years ago)
Author:
mdewsnip
Message:

Added a new command "get-all-chunks" for getting all of the chunks for a file, no matter whether they need translating or updating or not.

File:
1 edited

Legend:

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

    r13690 r13693  
    107107
    108108    # Process the command
     109    if ($gti_command =~ /^get-all-chunks$/i) {
     110    print &get_all_chunks(@gti_command_arguments);
     111    }
    109112    if ($gti_command =~ /^get-first-n-chunks-requiring-work$/i) {
    110113    print &get_first_n_chunks_requiring_work(@gti_command_arguments);
     
    146149    my $log_message = shift(@_);
    147150    print GTI_LOG time() . " -- " . $log_message . "\n";
     151}
     152
     153
     154sub get_all_chunks
     155{
     156    # The code of the target language (ensure it is lowercase)
     157    my $target_language_code = lc(shift(@_));
     158    # The key of the file to translate (ensure it is lowercase)
     159    my $translation_file_key = lc(shift(@_));
     160
     161    # Check that the necessary arguments were supplied
     162    if (!$target_language_code || !$translation_file_key) {
     163    &throw_fatal_error("Missing command argument.");
     164    }
     165
     166    # Get (and check) the translation configuration
     167    my ($source_file, $target_file, $translation_file_type)
     168    = &get_translation_configuration($target_language_code, $translation_file_key);
     169
     170    # Parse the source language and target language files
     171    my $source_file_path = &util::filename_cat($gsdl_root_directory, $source_file);
     172    my @source_file_lines = &read_file_lines($source_file_path);
     173    my %source_file_key_to_line_mapping = &build_key_to_line_mapping(\@source_file_lines, $translation_file_type);
     174
     175    my $target_file_path = &util::filename_cat($gsdl_root_directory, $target_file);
     176    my @target_file_lines = &read_file_lines($target_file_path);
     177    my %target_file_key_to_line_mapping = &build_key_to_line_mapping(\@target_file_lines, $translation_file_type);
     178
     179    # Filter out any automatically translated chunks
     180    foreach my $chunk_key (keys(%source_file_key_to_line_mapping)) {
     181    if (&is_chunk_automatically_translated($chunk_key, $translation_file_type)) {
     182        delete $source_file_key_to_line_mapping{$chunk_key};
     183        delete $target_file_key_to_line_mapping{$chunk_key};
     184    }
     185    }
     186
     187    my %source_file_key_to_text_mapping = &build_key_to_text_mapping(\@source_file_lines, \%source_file_key_to_line_mapping, $translation_file_type);
     188    my %target_file_key_to_text_mapping = &build_key_to_text_mapping(\@target_file_lines, \%target_file_key_to_line_mapping, $translation_file_type);
     189    &log_message("Number of source chunks: " . scalar(keys(%source_file_key_to_text_mapping)));
     190    &log_message("Number of target chunks: " . scalar(keys(%target_file_key_to_text_mapping)));
     191
     192    my %source_file_key_to_last_update_date_mapping = &build_key_to_last_update_date_mapping($source_file, \@source_file_lines, \%source_file_key_to_line_mapping, $translation_file_type);
     193    my %target_file_key_to_last_update_date_mapping = &build_key_to_last_update_date_mapping($target_file, \@target_file_lines, \%target_file_key_to_line_mapping, $translation_file_type);
     194
     195    # Form an XML response to the command
     196    my $xml_response = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     197    $xml_response .= "<GTIResponse>\n";
     198    $xml_response .= "  <TranslationFile"
     199    . " key=\"" . $translation_file_key . "\""
     200    . " target_file_path=\"" . $target_file . "\"\/>\n";
     201
     202    # Do all the chunks
     203    $xml_response .= "  <Chunks size=\"" . scalar(keys(%source_file_key_to_text_mapping)) . "\">\n";
     204    foreach my $chunk_key (keys(%source_file_key_to_text_mapping)) {
     205    my $source_file_chunk_date = $source_file_key_to_last_update_date_mapping{$chunk_key};
     206    my $source_file_chunk_text = &make_text_xml_safe($source_file_key_to_text_mapping{$chunk_key});
     207
     208    $xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";
     209    $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
     210    if (defined($target_file_key_to_text_mapping{$chunk_key})) {
     211        my $target_file_chunk_date = $target_file_key_to_last_update_date_mapping{$chunk_key};
     212        my $target_file_chunk_text = &make_text_xml_safe($target_file_key_to_text_mapping{$chunk_key});
     213        $xml_response .= "      <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n";
     214    }
     215    else {
     216        $xml_response .= "      <TargetFileText></TargetFileText>\n";
     217    }
     218
     219    $xml_response .= "    </Chunk>\n";
     220    }
     221    $xml_response .= "  </Chunks>\n";
     222
     223    $xml_response .= "</GTIResponse>\n";
     224    return $xml_response;
    148225}
    149226
Note: See TracChangeset for help on using the changeset viewer.