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