Language-Dashrep
view release on metacpan or search on metacpan
lib/Language/Dashrep.pm view on Meta::CPAN
if ( $qualifier eq "-parameters-only" )
{
$translation = &dashrep_expand_parameters( $input_line );
} elsif ( $qualifier eq "-phrases-only" )
{
$translation = &dashrep_expand_phrases( $input_line );
} elsif ( $qualifier eq "-special-phrases-only" )
{
$translation = &dashrep_expand_special_phrases( $input_line );
} else
{
$partial_translation = &dashrep_expand_parameters( $input_line );
$translation = &dashrep_expand_phrases( $partial_translation );
}
if ( ( $translation =~ /[^ ]/ ) && ( ( $global_ignore_level < 1 ) || ( $global_capture_level < 1 ) ) )
{
print OUTFILE $translation . "\n" ;
}
if ( $global_top_line_count_for_insert_phrase == 1 )
{
$global_top_line_count_for_insert_phrase = 2 ;
} elsif ( $global_top_line_count_for_insert_phrase == 2 )
{
$global_top_line_count_for_insert_phrase = 0 ;
if ( $global_phrase_to_insert_after_next_top_level_line ne "" )
{
$input_line = "[-" . $global_phrase_to_insert_after_next_top_level_line . "-]" ;
$lines_to_translate = 1 ;
}
}
}
}
}
if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
{
print "{{trace; linewise translated from file " . $source_filename . " to file " . $target_filename . "}}\n" ;
}
} else
{
if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
{
print "{{trace; failed to linewise translate from file " . $source_filename . " to file " . $target_filename . "}}\n" ;
}
}
close( INFILE ) ;
close( OUTFILE ) ;
$input_text = "" ;
#-----------------------------------------------
# Handle the action:
# linewise-translate-xml-tags-in-file-to-dashrep-phrases-in-file
#
# The output filename is edited to remove any path
# specifications, so that only local files
# are affected.
# If a tag does not end on the same line as it
# starts, more lines are read in an attempt
# to reach the end of the tag, but this
# capability is not robust. This is done to
# accomodate XHTML generated by the "Tidy"
# utility.
} elsif ( $input_text =~ /^ *linewise-translate-xml-tags-in-file-to-dashrep-phrases-in-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
{
$source_filename = $1 ;
$target_filename = $2 ;
$target_filename =~ s/^.*[\\\/]// ;
$target_filename =~ s/^\.+// ;
if ( open ( INFILE , "<" . $source_filename ) )
{
$possible_error_message .= "" ;
} else
{
$possible_error_message .= " [file named " . $source_filename . " not found, or could not be opened]" ;
}
if ( open ( OUTFILE , ">" . $target_filename ) )
{
$possible_error_message .= "" ;
} else
{
$possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
}
if ( $possible_error_message eq "" )
{
$full_line = "" ;
$multi_line_limit = 10 ;
while( $input_line = <INFILE> )
{
chomp( $input_line ) ;
$input_line =~ s/[\n\r\f\t]+/ /g ;
if ( $full_line ne "" )
{
$full_line = $full_line . " " . $input_line ;
} else
{
$full_line = $input_line ;
}
$open_brackets = $full_line ;
$close_brackets = $full_line ;
$open_brackets =~ s/[^<]//g ;
$close_brackets =~ s/[^>]//g ;
if ( ( length( $open_brackets ) != length( $close_brackets ) ) && ( $multi_line_count < $multi_line_limit ) )
{
next ;
}
if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
{
print "{{trace; accumulated text to convert: " . $full_line . "}}\n" ;
}
$global_endless_loop_counter = 0 ;
%global_replacement_count_for_item_name = ( ) ;
$translation = &dashrep_xml_tags_to_dashrep( $full_line );
print OUTFILE $translation . "\n" ;
$full_line = "" ;
}
if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
{
print "{{trace; source xml file named " . $source_filename . " expanded into dashrep phrases in file named " . $target_filename . "}}\n" ;
}
$global_dashrep_replacement{ "dashrep-list-of-xml-phrases" } = "" ;
( run in 1.604 second using v1.01-cache-2.11-cpan-677af5a14d3 )