Ignore:
Timestamp:
2007-02-26T09:30:24+13:00 (17 years ago)
Author:
nzdl
Message:

fixed the submitted source text changed problem

File:
1 edited

Legend:

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

    r13693 r13946  
    5656
    5757      # GLI dictionary
    58       # { 'key' => "glidict",
    59     # 'file_type' => "resource_bundle",
    60     # 'source_file' => "gli/classes/dictionary.properties",
    61     # 'target_file' => "gli/classes/dictionary_{target_language_code}.properties" },
     58      { 'key' => "glidict",
     59    'file_type' => "resource_bundle",
     60    'source_file' => "gli/classes/dictionary.properties",
     61    'target_file' => "gli/classes/dictionary_{target_language_code}.properties" },
    6262
    6363      # GLI help
    64       # { 'key' => "glihelp",
    65     # 'file_type' => "greenstone_xml",
    66     # 'source_file' => "gli/help/en/help.xml",
    67     # 'target_file' => "gli/help/{target_language_code}/help.xml" },
     64      { 'key' => "glihelp",
     65    'file_type' => "greenstone_xml",
     66    'source_file' => "gli/help/en/help.xml",
     67    'target_file' => "gli/help/{target_language_code}/help.xml" },
    6868
    6969      # Greenstone Perl modules
     
    7676      # { 'key' => "tutorials",
    7777    # 'file_type' => "greenstone_xml",
    78     # 'source_file' => "gsdl-tutorials/tutorial_en.xml",
    79     # 'target_file' => "gsdl-tutorials/tutorial_{target_language_code}.xml" },
     78    # 'source_file' => "gsdl-documentation/tutorials/xml-source/tutorial_en.xml",
     79    # 'target_file' => "gsdl-documentation/tutorials/xml-source/tutorial_{target_language_code}.xml" },
    8080
    8181      # Greenstone.org
    82       # { 'key' => "greenorg",
    83     # 'file_type' => "macrofile",
    84     # 'source_file' => "greenorg/macros/english.dm",
    85     # 'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm" }
     82      { 'key' => "greenorg",
     83    'file_type' => "macrofile",
     84    'source_file' => "greenorg/macros/english.dm",
     85    'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm" }
    8686    ];
    8787
     
    107107
    108108    # Process the command
    109     if ($gti_command =~ /^get-all-chunks$/i) {
    110     print &get_all_chunks(@gti_command_arguments);
    111     }
    112109    if ($gti_command =~ /^get-first-n-chunks-requiring-work$/i) {
    113110    print &get_first_n_chunks_requiring_work(@gti_command_arguments);
     
    149146    my $log_message = shift(@_);
    150147    print GTI_LOG time() . " -- " . $log_message . "\n";
    151 }
    152 
    153 
    154 sub 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;
    225148}
    226149
     
    588511
    589512    # Make sure the submitted source chunk matches the source file chunk
    590     if ($source_file_key_to_submission_mapping{$chunk_key} ne $source_file_key_to_text_mapping{$chunk_key}) {
     513    if ($source_file_key_to_submission_mapping{$chunk_key} ne &unmake_text_xml_safe($source_file_key_to_text_mapping{$chunk_key})) {
    591514        &log_message("Warning: Source chunk $chunk_key has changed (ignoring submission).");
    592515        &log_message("Submission source: $source_file_key_to_submission_mapping{$chunk_key}");
Note: See TracChangeset for help on using the changeset viewer.