Changeset 25249 for main/trunk/greenstone2
- Timestamp:
- 2012-03-22T21:44:44+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/bin/script/gti.pl
r24627 r25249 131 131 } 132 132 } 133 elsif ($gti_command =~ /^get-uptodate-chunks$/i) { 134 if ($module eq "gs3interface") { 135 print &get_uptodate_chunks_for_gs3(@gti_command_arguments); 136 } else { 137 print &get_uptodate_chunks(@gti_command_arguments); 138 } 139 } 133 140 elsif ($gti_command =~ /^get-language-status$/i) { 134 141 print &get_language_status(@gti_command_arguments); … … 218 225 my $xml_response = &create_xml_response_for_all_chunks($translation_file_key, $target_file, \%source_file_key_to_text_mapping, \%target_file_key_to_text_mapping, \%source_file_key_to_last_update_date_mapping, \%target_file_key_to_last_update_date_mapping); 219 226 227 return $xml_response; 228 } 229 230 231 sub get_uptodate_chunks 232 { 233 # The code of the target language (ensure it is lowercase) 234 my $target_language_code = lc(shift(@_)); 235 # The key of the file to translate (ensure it is lowercase) 236 my $translation_file_key = lc(shift(@_)); 237 238 # Check that the necessary arguments were supplied 239 if (!$target_language_code || !$translation_file_key) { 240 &throw_fatal_error("Missing command argument."); 241 } 242 243 # Get (and check) the translation configuration 244 my ($source_file, $target_file, $translation_file_type) 245 = &get_translation_configuration($target_language_code, $translation_file_key); 246 247 # Parse the source language and target language files 248 my $source_file_path = &util::filename_cat($gsdl_root_directory, $source_file); 249 my @source_file_lines = &read_file_lines($source_file_path); 250 my %source_file_key_to_line_mapping = &build_key_to_line_mapping(\@source_file_lines, $translation_file_type); 251 252 my $target_file_path = &util::filename_cat($gsdl_root_directory, $target_file); 253 my @target_file_lines = &read_file_lines($target_file_path); 254 my %target_file_key_to_line_mapping = &build_key_to_line_mapping(\@target_file_lines, $translation_file_type); 255 256 # Filter out any automatically translated chunks 257 foreach my $chunk_key (keys(%source_file_key_to_line_mapping)) { 258 if (&is_chunk_automatically_translated($chunk_key, $translation_file_type)) { 259 delete $source_file_key_to_line_mapping{$chunk_key}; 260 delete $target_file_key_to_line_mapping{$chunk_key}; 261 } 262 } 263 264 my %source_file_key_to_text_mapping = &build_key_to_text_mapping(\@source_file_lines, \%source_file_key_to_line_mapping, $translation_file_type); 265 my %target_file_key_to_text_mapping = &build_key_to_text_mapping(\@target_file_lines, \%target_file_key_to_line_mapping, $translation_file_type); 266 &log_message("Number of source chunks: " . scalar(keys(%source_file_key_to_text_mapping))); 267 &log_message("Number of target chunks: " . scalar(keys(%target_file_key_to_text_mapping))); 268 269 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); 270 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); 271 272 273 # Chunks needing updating are those in the target file that have been more recently edited in the source file 274 # All others are uptodate (which implies that they have certainly been translated at some point and would not be empty) 275 my @uptodate_target_file_keys = (); 276 foreach my $chunk_key (keys(%source_file_key_to_last_update_date_mapping)) { 277 my $source_chunk_last_update_date = $source_file_key_to_last_update_date_mapping{$chunk_key}; 278 my $target_chunk_last_update_date = $target_file_key_to_last_update_date_mapping{$chunk_key}; 279 280 # print "key: $chunk_key\nsource date : $source_chunk_last_update_date\ntarget date : $target_chunk_last_update_date\nafter? ". &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date) . "\n\n"; 281 282 if (defined($target_chunk_last_update_date) && !&is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) { 283 # &log_message("Chunk with key $chunk_key needs updating."); 284 push(@uptodate_target_file_keys, $chunk_key); 285 } 286 } 287 288 my $xml_response = &create_xml_response_for_uptodate_chunks($translation_file_key, $target_file, \@uptodate_target_file_keys, \%source_file_key_to_text_mapping, \%target_file_key_to_text_mapping, \%source_file_key_to_last_update_date_mapping, \%target_file_key_to_last_update_date_mapping); 289 220 290 return $xml_response; 221 291 } … … 1123 1193 } 1124 1194 1195 sub create_xml_response_for_uptodate_chunks 1196 { 1197 my ($translation_file_key, $target_file, $uptodate_target_files_keys, $source_files_key_to_text_mapping, $target_files_key_to_text_mapping, $source_files_key_to_last_update_date_mapping, $target_files_key_to_last_update_date_mapping) = @_; 1198 1199 # Form an XML response to the command 1200 my $xml_response = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; 1201 $xml_response .= "<GTIResponse>\n"; 1202 $xml_response .= " <TranslationFile" 1203 . " key=\"" . $translation_file_key . "\"" 1204 . " target_file_path=\"" . $target_file . "\"" 1205 . " num_chunks_uptodate=\"" . scalar(@$uptodate_target_files_keys) . "\"\/>\n"; 1206 1207 1208 # Then do chunks requiring updating 1209 $xml_response .= " <UptodateChunks size=\"" . scalar(@$uptodate_target_files_keys) . "\">\n"; 1210 1211 1212 # foreach my $chunk_key (@uptodate_target_file_keys) { 1213 my @sorted_chunk_keys = sort (@$uptodate_target_files_keys); 1214 foreach my $chunk_key (@sorted_chunk_keys) { 1215 1216 my $source_file_chunk_date = $source_files_key_to_last_update_date_mapping->{$chunk_key} || ""; 1217 my $source_file_chunk_text = &make_text_xml_safe($source_files_key_to_text_mapping->{$chunk_key}); 1218 my $target_file_chunk_date = $target_files_key_to_last_update_date_mapping->{$chunk_key} || ""; 1219 my $target_file_chunk_text = &make_text_xml_safe($target_files_key_to_text_mapping->{$chunk_key}); 1220 1221 $xml_response .= " <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n"; 1222 $xml_response .= " <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n"; 1223 $xml_response .= " <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n"; 1224 $xml_response .= " </Chunk>\n"; 1225 1226 } 1227 1228 $xml_response .= " </UptodateChunks>\n"; 1229 1230 $xml_response .= "</GTIResponse>\n"; 1231 1232 return $xml_response; 1233 } 1125 1234 1126 1235 sub create_xml_response_for_all_chunks … … 1716 1825 } 1717 1826 1827 sub get_uptodate_chunks_for_gs3 1828 { 1829 # The code of the target language (ensure it is lowercase) 1830 my $target_language_code = lc(shift(@_)); 1831 # The key of the file to translate (ensure it is lowercase) 1832 my $translation_file_key = lc(shift(@_)); 1833 # The number of chunks to return (defaults to one if not specified) 1834 my $num_chunks_to_return = shift(@_) || "1"; 1835 1836 # Check that the necessary arguments were supplied 1837 if (!$target_language_code || !$translation_file_key) { 1838 &throw_fatal_error("Missing command argument."); 1839 } 1840 1841 my %source_files_key_to_text_mapping = (); 1842 my %target_files_key_to_text_mapping = (); 1843 my %source_files_key_to_last_update_date_mapping = (); 1844 my %target_files_key_to_last_update_date_mapping = (); 1845 1846 &build_gs3_configuration($target_language_code, \%source_files_key_to_text_mapping, \%target_files_key_to_text_mapping, 1847 \%source_files_key_to_last_update_date_mapping, \%target_files_key_to_last_update_date_mapping); 1848 1849 1850 # Chunks needing updating are those in the target file that have been more recently edited in the source file 1851 # All others are uptodate (which implies that they have certainly been translated at some point and would not be empty) 1852 my @uptodate_target_file_keys = (); 1853 foreach my $chunk_key (keys(%source_files_key_to_last_update_date_mapping)) { 1854 my $source_chunk_last_update_date = $source_files_key_to_last_update_date_mapping{$chunk_key}; 1855 my $target_chunk_last_update_date = $target_files_key_to_last_update_date_mapping{$chunk_key}; 1856 1857 # print "key: $chunk_key\nsource date : $source_chunk_last_update_date\ntarget date : $target_chunk_last_update_date\nafter? ". &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date) . "\n\n"; 1858 1859 if (defined($target_chunk_last_update_date) && !&is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) { 1860 # &log_message("Chunk with key $chunk_key needs updating."); 1861 push(@uptodate_target_file_keys, $chunk_key); 1862 } 1863 } 1864 1865 my $xml_response = &create_xml_response_for_uptodate_chunks($translation_file_key, "", \@uptodate_target_file_keys, \%source_files_key_to_text_mapping, \%target_files_key_to_text_mapping, \%source_files_key_to_last_update_date_mapping, \%target_files_key_to_last_update_date_mapping); 1866 1867 return $xml_response; 1868 } 1718 1869 1719 1870
Note:
See TracChangeset
for help on using the changeset viewer.