forked from donnekgit/agoriad
/
index.php
193 lines (148 loc) · 6.04 KB
/
index.php
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Apertium alpha-testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
div { background-color : white; padding: 2px; border: black 2px solid; position: relative;}
body { background-color: white; padding: 2px; margin: 2px; }
.banner { background-color: white; margin: 2px; padding: 2px; }
.tranbox{ background-color: white; margin: 2px; padding: 2px; float: left; width: 33%; }
.outbox { background-color: white; margin: 2px; padding: 2px; float: right; width: 64%; }
.langchooser { background-color: white; margin: 2px; padding: 2px; width: 96%; text-align: right; align: center; border: 0px; font-size: 80% }
/*]]>*/
</style>
</head>
<body>
<div class="langchooser">
<a href="index.php?lang=af_ZA">af</a> ·
<a href="index.php?lang=cy_GB">cy</a> ·
<a href="index.php?lang=en_GB">en</a> ·
<a href="index.php?lang=ro_RO">ro</a> ·
<a href="index.php?lang=bs_BA">sh</a>
</div>
<div>
<?php
// set up language choice options and print a reminder
setlocale(LC_ALL, 0);
if($_GET["lang"]) {
$newLocale = setlocale(LC_ALL, $_GET["lang"] . '.UTF-8');
} else {
$newLocale = setlocale(LC_ALL, 'en_GB.UTF-8');
}
$domain = 'messages';
bindtextdomain($domain, "./locale");
textdomain($domain);
/*
print _("This page allows you to test the pre-alpha (from SVN) versions of Apertium data") . ". ";
print _("These data will probably not work more often than not") . ". ";
print _("Often the data are woefully incomplete and they are not supported in any way") . ".";
*/
?>
</div>
<div class="tranbox">
<form action=<?php print '"index.php?lang=' . $_GET["lang"] .'"'; ?> method="post">
<p>
<textarea cols="43" rows="9" name="inputarea"><?php print str_replace('\\', '', $_POST["inputarea"]); ?></textarea><br/>
<select name="direction">
<?php
// this section gets the list of language directions as given in the file "enabled" and displays it
// file() reads each line of the file into an array
// "enabled" includes each language pair direction, the language names, and the encoding
$enabled = file('enabled');
for($i = 0; $i < sizeof($enabled); $i++) {
if($enabled[$i][0] == '#') {
continue;
}
$line = explode(',', $enabled[$i]);
// pair,direction,source,target
$d_state = $_POST["direction"];
if(isset($_GET["direction"])) {
$d_state = $_GET["direction"];
}
if($d_state) { // maintain state
print '<option value="' . $line[1] . '" ';
if($line[1] == $d_state) {
print 'selected';
}
print '>' . _($line[2]) . ' → ' . _(trim($line[3])) . '</option>';
} else {
print '<option value="' . $line[1] . '">' . _($line[2]) . ' → ' . _(trim($line[3])) . '</option>';
}
}
?>
</select><br />
<label for="marcar">
<input id="marcar" value="1" name="marcar" type="checkbox" title="<?php print _('Check the box to mark unknown words'); ?>" <?php if($_POST["marcar"]) print 'checked'; ?> />
<?php print _('Mark unknown words'); ?>
</label> <br />
<label for="interm">
<input id="interm" value="1" name="interm" type="checkbox" title="<?php print _('Check the box to print the intermediate representation'); ?>" <?php if($_POST["interm"]) print 'checked'; ?> />
<?php print _('Print intermediate representation'); ?>
</label>
<input type="hidden" value="true" name="mangle"/><br/>
<input type="submit" value="<?php print _('Translate'); ?>"/>
</p>
</form>
<!-- What the symbols mean -->
<hr style="border: black 1px solid;"/>
<!--<p style="font-size: 8pt;">-->
<p>
<span style='color: #990000;'><code>*</code></span> — <?php print _('Word not found in source'); ?>.<br/>
<span style='color: #990000;'><code>#</code></span> — <?php print _('Word found but no inflection'); ?>.<br/>
<span style='color: #990000;'><code>@</code></span> — <?php print _('Word not found in target'); ?>.
</p>
<hr style="border: black 1px solid;"/>
<!--<p style="font-size: 8pt;">-->
<p>
<span style='color: #009900;'><code>^ $</code></span> — <?php print _('Lexical unit start/stop'); ?><br/>
<span style='color: #999900;'><code>{ }</code></span> — <?php print _('Chunk start/stop'); ?><br/>
</p>
<!-- SVG map of Apertium progress - not relevant here
<div align="center">
<p style="align: center;">
<a href="graph.svg" target="_new">
<img src="graph.png" width="300" border="0"/>
</a>
</p>
</div>
-->
</div> <!-- e -->
<div class="outbox"> <!-- b -->
<?php
// if the form has been submitted with something in it
if($_POST['mangle']) {
include('Apertium.php');
// the following selects the encoding to be used for the input text
$enabled = file('enabled');
$filesuf = '';
$encoding = 'latin1'; // FT default
// why have this as the default? all the languages now use utf-8
for($i = 0; $i < sizeof($enabled); $i++) {
$line = explode(',', $enabled[$i]);
// FT pair,direction,source,target
if(strstr($line[1], $_POST['direction'])) {
$filesuf = $line[0];
$encoding = trim($line[4]);
}
}
// set up an Apertium object with the relevant language pair,direction and encoding
$translator = new Apertium($filesuf, $_POST['direction'], $encoding);
// arrange to print intermediate representation if that is ticked
if($_POST["interm"]) {
$options['interm'] = true;
}
// arrange to mark unknown words if that is ticked
if($_POST["marcar"]) {
$options['marcar'] = true;
}
$options['display'] = true;
// pass the input data (as text, not html) + options to the Apertium object
$translator->translate($_POST['inputarea'], $options, 'txt');
}
?>
</div> <!-- e -->
</body>
</html>