Changeset 11321
- Timestamp:
- 2006-03-09T15:07:34+13:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/gti.pl
r11224 r11321 948 948 { 949 949 my $source_file = shift(@_); # Not used 950 my $source_file_lines = shift(@_);950 my @source_file_lines = @{shift(@_)}; 951 951 my $source_file_key_to_text_mapping = shift(@_); 952 952 my $target_file = shift(@_); 953 my $target_file_lines = shift(@_); # Not used953 my @target_file_lines = @{shift(@_)}; 954 954 my $target_file_key_to_text_mapping = shift(@_); 955 955 my $target_file_key_to_comment_date_mapping = shift(@_); … … 957 957 958 958 # Build a mapping from source file line to chunk key 959 my %source_file_key_to_line_mapping = &build_key_to_line_mapping_for_macrofile(@ $source_file_lines);959 my %source_file_key_to_line_mapping = &build_key_to_line_mapping_for_macrofile(@source_file_lines); 960 960 my %source_file_line_to_key_mapping = (); 961 961 foreach my $chunk_key (keys(%source_file_key_to_line_mapping)) { … … 966 966 967 967 # Build a mapping from target file line to chunk key 968 my %target_file_key_to_line_mapping = &build_key_to_line_mapping_for_macrofile(@ $target_file_lines);968 my %target_file_key_to_line_mapping = &build_key_to_line_mapping_for_macrofile(@target_file_lines); 969 969 my %target_file_line_to_key_mapping = (); 970 970 foreach my $chunk_key (keys(%target_file_key_to_line_mapping)) { … … 984 984 my $target_file_chunk_starting_line_number = (split(/-/, $target_file_line_keys[0]))[0]; 985 985 while ($target_file_line_number < $target_file_chunk_starting_line_number) { 986 my $target_file_line = @$target_file_lines[$target_file_line_number];986 my $target_file_line = $target_file_lines[$target_file_line_number]; 987 987 last if ($target_file_line =~ /^\# -- Missing translation: /); # We don't want to get into the macros 988 988 print TARGET_FILE $target_file_line; … … 999 999 my $source_file_chunk_finishing_line_number = (split(/-/, $line_key))[1]; 1000 1000 while ($source_file_line_number < $source_file_chunk_starting_line_number) { 1001 print TARGET_FILE @$source_file_lines[$source_file_line_number];1001 print TARGET_FILE $source_file_lines[$source_file_line_number]; 1002 1002 $source_file_line_number++; 1003 1003 } … … 1018 1018 1019 1019 # Grab the source chunk text 1020 my $source_file_chunk = @$source_file_lines[$source_file_chunk_starting_line_number];1020 my $source_file_chunk = $source_file_lines[$source_file_chunk_starting_line_number]; 1021 1021 for (my $l = ($source_file_chunk_starting_line_number + 1); $l <= $source_file_chunk_finishing_line_number; $l++) { 1022 $source_file_chunk .= @$source_file_lines[$l];1022 $source_file_chunk .= $source_file_lines[$l]; 1023 1023 } 1024 1024 … … 1065 1065 my (@file_lines) = @_; 1066 1066 1067 my % key_to_line_mapping = ();1067 my %chunk_key_to_line_mapping = (); 1068 1068 for (my $i = 0; $i < scalar(@file_lines); $i++) { 1069 1069 my $line = $file_lines[$i]; … … 1075 1075 1076 1076 # Map from chunk key to line 1077 $ key_to_line_mapping{$chunk_key} = $i . "-" . $i;1078 } 1079 } 1080 1081 return % key_to_line_mapping;1077 $chunk_key_to_line_mapping{$chunk_key} = $i . "-" . $i; 1078 } 1079 } 1080 1081 return %chunk_key_to_line_mapping; 1082 1082 } 1083 1083 … … 1119 1119 { 1120 1120 my $source_file = shift(@_); # Not used 1121 my $source_file_lines = shift(@_);1121 my @source_file_lines = @{shift(@_)}; 1122 1122 my $source_file_key_to_text_mapping = shift(@_); 1123 1123 my $target_file = shift(@_); 1124 my $target_file_lines = shift(@_); # Not used1124 my @target_file_lines = @{shift(@_)}; # Not used 1125 1125 my $target_file_key_to_text_mapping = shift(@_); 1126 1126 my $target_file_key_to_comment_date_mapping = shift(@_); … … 1128 1128 1129 1129 # Build a mapping from chunk key to source file line, and from source file line to chunk key 1130 my %source_file_key_to_line_mapping = &build_key_to_line_mapping_for_resource_bundle(@ $source_file_lines);1130 my %source_file_key_to_line_mapping = &build_key_to_line_mapping_for_resource_bundle(@source_file_lines); 1131 1131 my %source_file_line_to_key_mapping = (); 1132 1132 foreach my $chunk_key (keys(%source_file_key_to_line_mapping)) { … … 1147 1147 my $source_file_chunk_finishing_line_number = (split(/-/, $line_key))[1]; 1148 1148 while ($source_file_line_number < $source_file_chunk_starting_line_number) { 1149 print TARGET_FILE @$source_file_lines[$source_file_line_number];1149 print TARGET_FILE $source_file_lines[$source_file_line_number]; 1150 1150 $source_file_line_number++; 1151 1151 } … … 1173 1173 1174 1174 1175 # ========================================================================================== 1176 # GREENSTONE XML FUNCTIONS 1177 1178 sub build_key_to_line_mapping_for_greenstone_xml 1179 { 1180 my (@file_lines) = @_; 1181 1182 my %chunk_key_to_line_mapping = (); 1183 for (my $i = 0; $i < scalar(@file_lines); $i++) { 1184 my $line = $file_lines[$i]; 1185 $line =~ s/(\s*)$//; # Remove any nasty whitespace, carriage returns etc. 1186 1187 # Line contains a string to translate 1188 if ($line =~ /^\s*<Text id=\"(.*?)\">/) { 1189 my $chunk_key = $1; 1190 $line =~ s/\s*([^\\]\#[^\}]+)?$//; # Remove any comments and nasty whitespace 1191 1192 # While there is still text of the string to go... 1193 my $startline = $i; 1194 while ($line !~ /<\/Text>$/) { 1195 $i++; 1196 if ($i == scalar(@file_lines)) { 1197 &throw_fatal_error("Could not find end of string $chunk_key."); 1198 } 1199 $line = $file_lines[$i]; 1200 $line =~ s/\s*([^\\]\#[^\}]+)?$//; # Remove any comments and nasty whitespace 1201 } 1202 1203 # Map from chunk key to line 1204 $chunk_key_to_line_mapping{$chunk_key} = $startline . "-" . $i; 1205 } 1206 } 1207 1208 return %chunk_key_to_line_mapping; 1209 } 1210 1211 1212 sub import_chunk_from_greenstone_xml 1213 { 1214 my ($chunk_text) = @_; 1215 1216 # Simple: just remove the Text tags 1217 $chunk_text =~ s/^\s*<Text .*id=\"(.*?)\".*?>(\s*)//; 1218 $chunk_text =~ s/<\/Text>$//; 1219 1220 return $chunk_text; 1221 } 1222 1223 1224 sub get_greenstone_xml_chunk_comment_date 1225 { 1226 my ($chunk_text) = @_; 1227 1228 # Check for an "Updated DD-MMM-YYYY" comment at the end of the chunk 1229 # !! TO DO 1230 1231 return undef; 1232 } 1233 1234 1235 sub is_greenstone_xml_chunk_automatically_translated 1236 { 1237 # No greenstone XML chunks are automatically translated 1238 return 0; 1239 } 1240 1241 1242 sub write_translated_greenstone_xml 1243 { 1244 my $source_file = shift(@_); # Not used 1245 my @source_file_lines = @{shift(@_)}; 1246 my $source_file_key_to_text_mapping = shift(@_); 1247 my $target_file = shift(@_); 1248 my @target_file_lines = @{shift(@_)}; # Not used 1249 my $target_file_key_to_text_mapping = shift(@_); 1250 my $target_file_key_to_comment_date_mapping = shift(@_); 1251 my $target_language_code = shift(@_); # Not used 1252 1253 # Build a mapping from chunk key to source file line, and from source file line to chunk key 1254 my %source_file_key_to_line_mapping = &build_key_to_line_mapping_for_greenstone_xml(@source_file_lines); 1255 my %source_file_line_to_key_mapping = (); 1256 foreach my $chunk_key (keys(%source_file_key_to_line_mapping)) { 1257 $source_file_line_to_key_mapping{$source_file_key_to_line_mapping{$chunk_key}} = $chunk_key; 1258 } 1259 1260 # Write the new target file 1261 my $target_file_path = &util::filename_cat($gsdl_root_directory, $target_file); 1262 if (!open(TARGET_FILE, ">$target_file_path")) { 1263 &throw_fatal_error("Could not write target file $target_file_path."); 1264 } 1265 1266 # Model the new target file on the source file, with the target file translations 1267 my $source_file_line_number = 0; 1268 foreach my $line_key (sort sort_by_line (keys(%source_file_line_to_key_mapping))) { 1269 # Fill in the gaps before this chunk starts 1270 my $source_file_chunk_starting_line_number = (split(/-/, $line_key))[0]; 1271 my $source_file_chunk_finishing_line_number = (split(/-/, $line_key))[1]; 1272 while ($source_file_line_number < $source_file_chunk_starting_line_number) { 1273 print TARGET_FILE $source_file_lines[$source_file_line_number]; 1274 $source_file_line_number++; 1275 } 1276 $source_file_line_number = $source_file_chunk_finishing_line_number + 1; 1277 1278 my $chunk_key = $source_file_line_to_key_mapping{$line_key}; 1279 my $source_file_chunk_text = $source_file_key_to_text_mapping->{$chunk_key}; 1280 my $target_file_chunk_text = $target_file_key_to_text_mapping->{$chunk_key} || ""; 1281 1282 # If no translation exists for this chunk, show this, and move on 1283 if ($source_file_chunk_text ne "" && $target_file_chunk_text eq "") { 1284 print TARGET_FILE "<!-- Missing translation: $chunk_key -->\n"; 1285 next; 1286 } 1287 1288 print TARGET_FILE "<Text id=\"$chunk_key\">$target_file_chunk_text</Text>"; 1289 if ($target_file_key_to_comment_date_mapping->{$chunk_key}) { 1290 # print TARGET_FILE " # Updated " . $target_file_key_to_comment_date_mapping->{$chunk_key}; 1291 } 1292 print TARGET_FILE "\n"; 1293 } 1294 1295 # Fill in the end of the file 1296 while ($source_file_line_number < scalar(@source_file_lines)) { 1297 print TARGET_FILE $source_file_lines[$source_file_line_number]; 1298 $source_file_line_number++; 1299 } 1300 1301 close(TARGET_FILE); 1302 } 1303 1304 1175 1305 &main(@ARGV);
Note:
See TracChangeset
for help on using the changeset viewer.