User:Pipesmoker/SyntaxHighlighting: Difference between revisions
Pipesmoker (talk | contribs) (Created page with "<syntaxhighlight lang="php"> #!/usr/bin/perl use Email::MIME; my $from_language = 'en'; my $to_language = '<translate><!--T:141--> he</translate>'; my $translation_command = "t...") |
Pipesmoker (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<syntaxhighlight lang=" | {{Input|1=<syntaxhighlight lang="perl"> | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
Line 5: | Line 5: | ||
my $from_language = 'en'; | my $from_language = 'en'; | ||
my $to_language = ' | my $to_language = 'he'; | ||
he | |||
my $translation_command = "translate "; | my $translation_command = "translate "; | ||
my $languages_pair = "-f $from_language -t $to_language"; | my $languages_pair = "-f $from_language -t $to_language"; | ||
Line 48: | Line 47: | ||
} | } | ||
print $email->as_string; | print $email->as_string; | ||
</syntaxhighlight> | </syntaxhighlight>}} |
Latest revision as of 11:44, 17 October 2010
#!/usr/bin/perl use Email::MIME; my $from_language = 'en'; my $to_language = 'he'; my $translation_command = "translate "; my $languages_pair = "-f $from_language -t $to_language"; my $line; my $message=''; while ($line=<>) { $message.=$line; } my $email = Email::MIME->new($message); my @parts = $email->parts; my $separator = `echo "translation" | $translation_command -f en -t "$to_language" -`; chop $separator; rec_parts ($email,@parts); sub rec_parts { my $parent = $_[0]; my @parts = $_[1]; for $part(@parts) { my @sub_parts = $part->parts; if (@sub_parts > 1) { rec_parts ($part,@sub_parts); } my $type=$part->content_type; if (( $part->content_type =~ m[text/plain]gi )||( $part->content_type eq '')) { my $body = $part->body; $body=~s/['"`]*//g; my $translation_body=`echo "$body" | $translation_command $languages_pair -`; $translation_body=~s/['"`]*//g; my $msg=$body."\n\n---"."$separator"."---\n\n".$translation_body; `kdialog --title "$separator" --msgbox "$msg"`; } } } print $email->as_string;