#!/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 TMX format # File name: csvtmx.pl # # Instructions # Change name of input file, source and target language # as required. # Run from command prompt perl csvtmx.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, ">>lingualizerTM.tmx") or die ("Cannot open file!"); # Creation of header for output file print TM '' . "\n"; print TM '' ."\n"; print TM '' ."\n"; print TM "". "\n"; 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 '="Att::Client">Generic' . "\n"; print TM '"Txt::Job #">L1001' ."\n"; print TM '' . "\n"; print TM "$SourceFull\n"; print TM "\n"; print TM '' . "\n"; print TM "$TargetFull\n"; print TM "\n"; print TM "\n\n"; } # Closing output file close (TM);