-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCombinations.pl
138 lines (124 loc) · 4.1 KB
/
CreateCombinations.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/perl
# Written by M. Paramita ([email protected])
# Last update 16 August 2011
use strict;
use warnings;
my $temp = "@ARGV";
if (scalar @ARGV < 18) {
print "Missing parameter. Please run the tool based on the guideline below.\n\n";
print "-------------------------------------------------------------------------------------------------------\n";
print "To run this script, please use the following arguments:\n\n";
print " \"perl CreateCombinations.pl --source [sourceLang] --target [targetLang] --sourceFile [sourceFile]\n";
print " --targetFile [targetFile] --sourcetranslation [sourceTranslationFile] --sourcehtml [sourceHTMLFile]\n";
print " --targettranslation [targetTranslationFile] --targethtml [targetHTMLFile] --metadata [outputmetadataFile]\n";
print "-------------------------------------------------------------------------------------------------------\n";
exit;
}
my ($sourceFile, $targetFile, $metadataFile, $sourceTranslationFile, $targetTranslationFile, $sourceHTMLFile, $targetHTMLFile, $sourceLang, $targetLang);
for (my $i=0; $i < scalar @ARGV; $i = $i+2) {
if ($ARGV[$i] eq "--source") {
$sourceLang = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--target") {
$targetLang = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--sourceFile") {
$sourceFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--targetFile") {
$targetFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--metadata") {
$metadataFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--sourcetranslation") {
$sourceTranslationFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--targettranslation") {
$targetTranslationFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--sourcehtml") {
$sourceHTMLFile = $ARGV[$i+1];
}
elsif ($ARGV[$i] eq "--targethtml") {
$targetHTMLFile = $ARGV[$i+1];
}
else {
print "53: Format $ARGV[$i] is not recognized. Please correct the format and restart the tool.\n";
exit();
}
}
my @sourceList = ();
my @targetList = ();
my @sourceTranslations = ();
my @targetTranslations = ();
my @sourceHTML = ();
my @targetHTML = ();
my %combinations = ();
#load source file list
open INPUT, "<:utf8", $sourceFile or die "Cannot open file $sourceFile.\n";
while (<INPUT>) {
chomp($_);
push(@sourceList, $_);
}
close INPUT;
#load target file list
open INPUT, "<:utf8", $targetFile or die "Cannot open file $targetFile.\n";
while (<INPUT>) {
chomp($_);
push(@targetList, $_);
}
close INPUT;
#load source translations
open INPUT, "<:utf8", $sourceTranslationFile or die "Cannot open file $sourceTranslationFile.\n";
while (<INPUT>) {
chomp($_);
push(@sourceTranslations, $_);
}
close INPUT;
#load target translations
open INPUT, "<:utf8", $targetTranslationFile or die "Cannot open file $targetTranslationFile.\n";
while (<INPUT>) {
chomp($_);
push(@targetTranslations, $_);
}
close INPUT;
#load source html
open INPUT, "<:utf8", $sourceHTMLFile or die "Cannot open file $sourceHTMLFile.\n";
while (<INPUT>) {
chomp($_);
push(@sourceHTML, $_);
}
close INPUT;
#load target html
open INPUT, "<:utf8", $targetHTMLFile or die "Cannot open file $targetHTMLFile.\n";
while (<INPUT>) {
chomp($_);
push(@targetHTML, $_);
}
close INPUT;
open OUTPUT, ">:utf8", $metadataFile or die "Cannot open file $metadataFile.\n";
for (my $i = 0; $i < scalar @sourceList; $i++) {
my $sourceFile = $sourceList[$i];
for (my $j = 0; $j < scalar @targetList; $j++) {
my $targetFile = $targetList[$j];
if (exists $combinations{"$sourceFile\t$targetFile"}) {
}
else {
$combinations{"$sourceFile\t$targetFile"} = 1;
my $translatedSource = $sourceTranslations[$i];
my $translatedTarget = "";
if ($targetLang eq "EN") {
$translatedTarget = $targetFile;
}
else {
$translatedTarget = $targetTranslations[$j];
}
#if the target language is EN, use the original file as the translation
my $htmlSource = $sourceHTML[$i];
my $htmlTarget = $targetHTML[$j];
print OUTPUT "$sourceFile\t$translatedSource\t$htmlSource\t\t$targetFile\t$translatedTarget\t$htmlTarget\t\n";
}
}
}
close OUTPUT;