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