Rev 232 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
223 | PointedEar | 1 | <!DOCTYPE html> |
289 | PointedEar | 2 | <html lang="en"> |
223 | PointedEar | 3 | <head> |
4 | <meta charset="UTF-8"> |
||
232 | PointedEar | 5 | <title>Golic Vulcan – Federation Standard English Dictionary</title> |
223 | PointedEar | 6 | <style type="text/css"> |
230 | PointedEar | 7 | body { |
8 | font-family: serif; |
||
9 | } |
||
10 | |||
11 | ol |
||
12 | { |
||
223 | PointedEar | 13 | padding-left: 0; |
14 | list-style-type: none; |
||
15 | } |
||
16 | |||
230 | PointedEar | 17 | ol li |
18 | { |
||
223 | PointedEar | 19 | margin-left: 0; |
20 | } |
||
21 | |||
230 | PointedEar | 22 | ol ol |
23 | { |
||
223 | PointedEar | 24 | padding-left: 1em; |
25 | } |
||
230 | PointedEar | 26 | |
27 | .type-or-context { |
||
28 | font-family: sans-serif; |
||
29 | font-size: small; |
||
30 | font-weight: bold; |
||
31 | } |
||
32 | |||
289 | PointedEar | 33 | <?php |
34 | $source_lang = 'vuh-Latn-Gol'; |
||
35 | ?> |
||
36 | i[lang="<?php echo $source_lang; ?>"] { |
||
37 | font-style: normal; |
||
38 | } |
||
39 | |||
230 | PointedEar | 40 | i em { |
41 | font-weight: bold; |
||
42 | } |
||
289 | PointedEar | 43 | |
44 | #toggle { |
||
45 | position: fixed; |
||
46 | top: 0; |
||
47 | right: 0; |
||
48 | } |
||
223 | PointedEar | 49 | </style> |
289 | PointedEar | 50 | <script type="text/javascript" src="/scripts/object.js"></script> |
51 | <script type="text/javascript" src="/scripts/dom/xpath.js"></script> |
||
52 | <script type="text/javascript">var LANG_VULCAN = '<?php echo $source_lang; ?>';</script> |
||
53 | <script type="text/javascript" src="/application/scripts/vulcan-media-script.js"></script> |
||
54 | </head> |
||
223 | PointedEar | 55 | |
289 | PointedEar | 56 | <body onload="document.getElementById('toggle').click()"> |
230 | PointedEar | 57 | <?php |
223 | PointedEar | 58 | $target_lang = 'en-Latn-Federation'; |
232 | PointedEar | 59 | $lines = file('vuh-gol-en.dict'); |
230 | PointedEar | 60 | ?> |
232 | PointedEar | 61 | <h1>Golic Vulcan – Federation Standard English Dictionary</h1> |
289 | PointedEar | 62 | <button type="button" id="toggle" onclick="mediaScript(this)"><span class="text">Media Script</span></button> |
230 | PointedEar | 63 | <?php |
64 | define('REGEXP_PREFIX_EXAMPLE', '/^ex\s*=\s*/'); |
||
223 | PointedEar | 65 | |
66 | if ($lines) |
||
67 | { |
||
68 | $last_indent = -1; |
||
69 | $last_phrases = array(); |
||
70 | |||
71 | foreach ($lines as $line) |
||
72 | { |
||
73 | preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches); |
||
74 | // var_dump($matches); |
||
75 | if ($matches) |
||
76 | { |
||
77 | $phrase = $matches['phrase']; |
||
78 | |||
79 | if (mb_strpos($phrase, '#') === false) |
||
80 | { |
||
81 | $indent = mb_strlen($matches['lws']) / 2; |
||
82 | |||
83 | if ($indent > $last_indent) |
||
84 | { |
||
85 | echo '<ol>'; |
||
86 | } |
||
87 | else |
||
88 | { |
||
89 | echo str_repeat('</ol>', $last_indent - $indent); |
||
90 | } |
||
91 | |||
92 | echo '<li>'; |
||
93 | |||
94 | $is_example = preg_match(REGEXP_PREFIX_EXAMPLE, $phrase); |
||
95 | if ($is_example) |
||
96 | { |
||
97 | $phrase = preg_replace(REGEXP_PREFIX_EXAMPLE, '', $phrase); |
||
98 | } |
||
99 | |||
100 | if ($indent > $last_indent) |
||
101 | { |
||
102 | $last_phrases[] = $phrase; |
||
103 | } |
||
104 | else if ($indent < $last_indent) |
||
105 | { |
||
106 | $last_phrases = array_slice($last_phrases, 0, $indent + 1); |
||
107 | } |
||
108 | |||
109 | if ($indent <= $last_indent) |
||
110 | { |
||
111 | $last_phrases[count($last_phrases) - 1] = $phrase; |
||
112 | } |
||
113 | |||
114 | $phrase = preg_replace( |
||
115 | array( |
||
116 | '/~/', |
||
117 | '/[()]/', |
||
118 | ), |
||
119 | array( |
||
120 | '=', |
||
121 | '|', |
||
122 | ), |
||
123 | $phrase); |
||
124 | |||
125 | if ($last_phrases) |
||
126 | { |
||
127 | end($last_phrases); |
||
128 | |||
129 | while (($last_phrase = prev($last_phrases)) !== false) |
||
130 | { |
||
131 | while (mb_strlen($last_phrase) > 1) |
||
132 | { |
||
133 | if (preg_match('/' . preg_quote($last_phrase) . '/i', |
||
134 | $phrase, $last_sub_matches)) |
||
135 | { |
||
136 | $phrase = preg_replace('/' . $last_sub_matches[0] . '/i', |
||
137 | '<u>\\0</u>', $phrase); |
||
138 | break 2; |
||
139 | } |
||
140 | |||
141 | $last_phrase = mb_strcut($last_phrase, 0, mb_strlen($last_phrase) - 1); |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | |||
146 | $transl = preg_replace( |
||
147 | array( |
||
148 | '/"([^"]+)"/', |
||
230 | PointedEar | 149 | '/\{([^\}]+)\}/', |
150 | '/(^|[\\s+\\[])\\/([\\s\\w\'()-]+)\\/(?=[,.;:\\s+\\]]|$)/u', |
||
223 | PointedEar | 151 | '/\|(.*)(?<!\|)/', |
230 | PointedEar | 152 | '/\*(.+?)\*/', |
223 | PointedEar | 153 | '/\\s+~/', |
154 | ), |
||
155 | array( |
||
156 | '“\\1”', |
||
230 | PointedEar | 157 | '<abbr class="type-or-context" lang="' . $target_lang . '">\\1</abbr>', |
289 | PointedEar | 158 | '\\1<i lang="' . $source_lang . '" class="text">\\2</i>', |
223 | PointedEar | 159 | '/\\1', |
230 | PointedEar | 160 | '<em>\\1</em>', |
223 | PointedEar | 161 | ' ~', |
162 | ), |
||
224 | PointedEar | 163 | $matches['transl']); |
223 | PointedEar | 164 | |
289 | PointedEar | 165 | echo ($is_example ? "<i lang='$source_lang' class='text'>" : "<b lang='$source_lang' class='text'>") |
223 | PointedEar | 166 | . $phrase |
167 | . ($is_example ? '</i>' : '</b>') |
||
168 | . " <span lang='$target_lang'>" . $transl . '</span>'; |
||
169 | |||
170 | $last_indent = $indent; |
||
171 | } |
||
172 | } |
||
173 | } |
||
230 | PointedEar | 174 | echo '</ol>'; |
175 | |||
176 | // $phrases = array(); |
||
177 | |||
178 | // foreach ($lines as $line) |
||
179 | // { |
||
180 | // preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches); |
||
181 | // if ($matches) |
||
182 | // { |
||
183 | // $phrase = $matches['phrase']; |
||
184 | |||
185 | // /* if not a comment */ |
||
186 | // if (mb_strpos($phrase, '#') === false) |
||
187 | // { |
||
188 | // $transl = $matches['transl']; |
||
189 | |||
190 | // $is_example = preg_match(REGEXP_PREFIX_EXAMPLE, $phrase); |
||
191 | // if ($is_example) |
||
192 | // { |
||
193 | // /* assign example to previous phrase; indentation irrelevant */ |
||
194 | // $phrase = preg_replace(REGEXP_PREFIX_EXAMPLE, '', $phrase); |
||
195 | |||
196 | // $prev_phrase['examples'][$phrase] = $transl; |
||
197 | // } |
||
198 | // else |
||
199 | // { |
||
200 | // /* create new phrase */ |
||
201 | // $level = mb_strlen($matches['lws']) / 2; |
||
202 | |||
203 | // $phrases[$phrase] = array( |
||
204 | // 'translation' => $transl, |
||
205 | // 'level' => $level |
||
206 | // ); |
||
207 | // $prev_phrase =& $phrases[$phrase]; |
||
208 | // } |
||
209 | // } |
||
210 | // } |
||
211 | // } |
||
212 | |||
213 | // // var_dump($phrases); |
||
214 | |||
215 | // if ($phrases) |
||
216 | // { |
||
217 | // $prev_level = -1; |
||
218 | |||
219 | // foreach ($phrases as $phrase => $data) |
||
220 | // { |
||
221 | // $level = $data['level']; |
||
222 | |||
223 | // if ($level > $prev_level) |
||
224 | // { |
||
225 | // echo "\n<ol>\n"; |
||
226 | // } |
||
227 | // else if ($level < $prev_level) |
||
228 | // { |
||
229 | // echo str_repeat("</ol>\n", $prev_level - $level); |
||
230 | // } |
||
231 | |||
232 | // $translation = $data['translation']; |
||
233 | |||
234 | // echo "\n<li>$prev_level => $level <b lang='$source_lang'>" . htmlspecialchars($phrase) . '</b>' |
||
235 | // . " <span lang='$target_lang'>" . $translation . '</span>'; |
||
236 | |||
237 | // if (isset($data['examples'])) |
||
238 | // { |
||
239 | // echo '<ul>'; |
||
240 | |||
241 | // foreach ($data['examples'] as $original => $translation) |
||
242 | // { |
||
243 | // echo "<li><i lang='$source_lang'>" . htmlspecialchars($original) . '</i>' |
||
244 | // . " <span lang='$target_lang'>" . $translation . '</span></li>'; |
||
245 | // } |
||
246 | |||
247 | // echo '</ul>'; |
||
248 | // } |
||
249 | |||
250 | // $prev_level = $level; |
||
251 | // } |
||
252 | |||
253 | // echo '</ol>'; |
||
254 | // } |
||
223 | PointedEar | 255 | ?> |
230 | PointedEar | 256 | <?php } ?> |
223 | PointedEar | 257 | </body> |
258 | </html> |