#!/usr/bin/perl use warnings; ##Objective is to translate Spanish Prompts to English Prompts ## FIL filename for translation $fileone="COM_211_RAD_07A_ES_MX.FIL"; ## LAN filename for translation $filetwo="test.lan"; ## Debug file to be translated $filetotranslate = "test.txt"; ## English to Spanish translations file $fileout="out.txt"; $fileout2="out2.txt"; ## Debug file with translated from Spanish to English $fileout3="debug.txt"; ## Open the lan file to read in the English and Spanish words ##open (FILEIN, $fileone) or die "Can't open first file.\n";; ## Read in each line and create a hash table ##while ($linein = ) { ## chomp $linein; ## @arrayin = split /\|/, $linein; ##creates an array with split function using | as separator ## $englishword = $arrayin[0]; ## $spanishword = $arrayin[1]; ## print "$englishword -> $spanishword\n"; ## $langhash{$spanishword} = $englishword; ## print "$langhash{$spanishword}\n"; ##} ##close(FINEIN); ## Open Lan file to read in the English and Spanish words open (FILEIN2, $filetwo) or die "Can't open debug file to be translated.\n";; open (FILEOUT, ">$fileout2") or die "Can't open output file.\n";; ## Go through each line and replace while ($linein = ) { chomp $linein; @arrayin = split /:/, $linein; ##creates an array with split function using : as separator if ($arrayin[0] eq "Default") { $englishword = $arrayin[1]; } if ($arrayin[0] eq "Spanish_LatinAmerican|es_MX") { $spanishword = $arrayin[1]; } if ($arrayin[0] eq "Spanish_LatinAmerican|es_MX") { $langhash{$spanishword} = $englishword; ## print FILEOUT "$englishword -> $spanishword\n"; }} while (($spanishword, $englishword) = each %langhash){ ##Print entire hash table print FILEOUT "$spanishword=>$englishword\n"; } close(FILEIN2); close(FILEOUT); ## Open debug file to convert from English to Spanish open (FILEIN3, $filetotranslate) or die "Can't open debug file.\n"; open (FILEOUT3, ">$fileout3") or die "Can't open output file.\n"; ## Go through each line and replace while ($linein3 = ) { if ($linein3 =~ /##\s*([^#]+?)\s*##/){ if (exists ($langhash{$1})){ $linein3=~ s/##\s*([^#]+?)\s*##/##$langhash{$1}##/; print FILEOUT3 "$linein3"; } else { $linein3=~ s/##\s*([^#]+?)\s*##/##$1##/; print FILEOUT3 "$linein3"; }}} close(FILEIN3); close(FILEOUT3);