#!/usr/bin/perl # Copyright 13th. October 2008, Cotman University # http://www.cotmanuniversity.com # Created by Dr. Peter Kjeldsen # Department for Computational Linguistics # Conversion of CVS format to Trados Text TM format # File name: csvtratext.pl # # Instructions # Change name of input file, source and target language # as required. # Run from command prompt perl csvtratext.pl # # Setting up formated variable for handling date and time ($sec, $min, $hour, $mday, $mon, $year) = localtime(time); $mon++; $year+= 1900; $hour = sprintf("%02d", $hour); $min = sprintf("%02d", $min); $sec = sprintf("%02d", $sec); # Opening input file open (TXT, "; close (TXT); # Opening/creating output file open (TM, ">>lingualizertradosTM.txt") or die ("Cannot open file!"); # Creating header for output file $hoved = '' . "\n"; print TM $hoved; print TM "\n"; print TM "\n"; print TM "\n"; # Looping through input file content line by line foreach $lines(@text) { # Splitting line content and creating translation units @line = split (/","/, $lines); # Chopping leading " from source string by reversing, chopping and reversing $words = reverse($line[0]); $char = chop($words); $rev2str = reverse($words); $CleanSource = $rev2str; # Creating the source element of the translation unit $SourceFull = '' . $CleanSource; # Chopping \n from the end of target string $char = chop($line[1]); $TargetChop = $line[1]; # Chopping " from the end of the target string $char = chop($TargetChop); $CleanTarget = $TargetChop; # Creating the target element of the translation unit $TargetFull = '' . $CleanTarget; print TM "\n"; print TM " $mday" . "$mon" . "$year, $hour:$min:$sec" . "\n"; print TM "Lingualizer\n"; print TM "$SourceFull\n"; print TM "$TargetFull\n"; print TM "\n"; } # Closing output file close (TM);