Rev 230 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 223 | PointedEar | 1 | <!DOCTYPE html>  | 
        
| 2 | <html lang="en"">  | 
        ||
| 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 | |||
| 33 |       i em { | 
        ||
| 34 | font-weight: bold;  | 
        ||
| 35 | }  | 
        ||
| 223 | PointedEar | 36 | </style>  | 
        
| 37 | </head>  | 
        ||
| 38 | |||
| 39 | <body>  | 
        ||
| 230 | PointedEar | 40 | <?php | 
        
| 232 | PointedEar | 41 | $source_lang = 'vuh-Latn-Gol';  | 
        
| 223 | PointedEar | 42 | $target_lang = 'en-Latn-Federation';  | 
        
| 232 | PointedEar | 43 | $lines = file('vuh-gol-en.dict');  | 
        
| 230 | PointedEar | 44 | ?> | 
        
| 232 | PointedEar | 45 | <h1>Golic Vulcan – Federation Standard English Dictionary</h1>  | 
        
| 230 | PointedEar | 46 |       <?php | 
        
| 47 | define('REGEXP_PREFIX_EXAMPLE', '/^ex\s*=\s*/');  | 
        ||
| 223 | PointedEar | 48 | |
| 49 | if ($lines)  | 
        ||
| 50 |         { | 
        ||
| 51 | $last_indent = -1;  | 
        ||
| 52 | $last_phrases = array();  | 
        ||
| 53 | |||
| 54 | foreach ($lines as $line)  | 
        ||
| 55 |           { | 
        ||
| 56 | preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches);  | 
        ||
| 57 | // var_dump($matches); | 
        ||
| 58 | if ($matches)  | 
        ||
| 59 |             { | 
        ||
| 60 | $phrase = $matches['phrase'];  | 
        ||
| 61 | |||
| 62 | if (mb_strpos($phrase, '#') === false)  | 
        ||
| 63 |               { | 
        ||
| 64 | $indent = mb_strlen($matches['lws']) / 2;  | 
        ||
| 65 | |||
| 66 | if ($indent > $last_indent)  | 
        ||
| 67 |                 { | 
        ||
| 68 | echo '<ol>';  | 
        ||
| 69 |                 } | 
        ||
| 70 |                 else | 
        ||
| 71 |                 { | 
        ||
| 72 | echo str_repeat('</ol>', $last_indent - $indent);  | 
        ||
| 73 |                 } | 
        ||
| 74 | |||
| 75 | echo '<li>';  | 
        ||
| 76 | |||
| 77 | $is_example = preg_match(REGEXP_PREFIX_EXAMPLE, $phrase);  | 
        ||
| 78 | if ($is_example)  | 
        ||
| 79 |                 { | 
        ||
| 80 | $phrase = preg_replace(REGEXP_PREFIX_EXAMPLE, '', $phrase);  | 
        ||
| 81 |                 } | 
        ||
| 82 | |||
| 83 | if ($indent > $last_indent)  | 
        ||
| 84 |                 { | 
        ||
| 85 | $last_phrases[] = $phrase;  | 
        ||
| 86 |                 } | 
        ||
| 87 | else if ($indent < $last_indent)  | 
        ||
| 88 |                 { | 
        ||
| 89 | $last_phrases = array_slice($last_phrases, 0, $indent + 1);  | 
        ||
| 90 |                 } | 
        ||
| 91 | |||
| 92 | if ($indent <= $last_indent)  | 
        ||
| 93 |                 { | 
        ||
| 94 | $last_phrases[count($last_phrases) - 1] = $phrase;  | 
        ||
| 95 |                 } | 
        ||
| 96 | |||
| 97 | $phrase = preg_replace(  | 
        ||
| 98 | array(  | 
        ||
| 99 | '/~/',  | 
        ||
| 100 | '/[()]/',  | 
        ||
| 101 | ),  | 
        ||
| 102 | array(  | 
        ||
| 103 | '=',  | 
        ||
| 104 | '|',  | 
        ||
| 105 | ),  | 
        ||
| 106 | $phrase);  | 
        ||
| 107 | |||
| 108 | if ($last_phrases)  | 
        ||
| 109 |                 { | 
        ||
| 110 | end($last_phrases);  | 
        ||
| 111 | |||
| 112 | while (($last_phrase = prev($last_phrases)) !== false)  | 
        ||
| 113 |                   { | 
        ||
| 114 | while (mb_strlen($last_phrase) > 1)  | 
        ||
| 115 |                     { | 
        ||
| 116 | if (preg_match('/' . preg_quote($last_phrase) . '/i',  | 
        ||
| 117 | $phrase, $last_sub_matches))  | 
        ||
| 118 |                       { | 
        ||
| 119 | $phrase = preg_replace('/' . $last_sub_matches[0] . '/i',  | 
        ||
| 120 | '<u>\\0</u>', $phrase);  | 
        ||
| 121 | break 2;  | 
        ||
| 122 |                       } | 
        ||
| 123 | |||
| 124 | $last_phrase = mb_strcut($last_phrase, 0, mb_strlen($last_phrase) - 1);  | 
        ||
| 125 |                     } | 
        ||
| 126 |                   } | 
        ||
| 127 |                 } | 
        ||
| 128 | |||
| 129 | $transl = preg_replace(  | 
        ||
| 130 | array(  | 
        ||
| 131 | '/"([^"]+)"/',  | 
        ||
| 230 | PointedEar | 132 | '/\{([^\}]+)\}/',  | 
        
| 133 | '/(^|[\\s+\\[])\\/([\\s\\w\'()-]+)\\/(?=[,.;:\\s+\\]]|$)/u',  | 
        ||
| 223 | PointedEar | 134 | '/\|(.*)(?<!\|)/',  | 
        
| 230 | PointedEar | 135 | '/\*(.+?)\*/',  | 
        
| 223 | PointedEar | 136 | '/\\s+~/',  | 
        
| 137 | ),  | 
        ||
| 138 | array(  | 
        ||
| 139 | '“\\1”',  | 
        ||
| 230 | PointedEar | 140 | '<abbr class="type-or-context" lang="' . $target_lang . '">\\1</abbr>',  | 
        
| 141 | '\\1<i lang="' . $source_lang . '">\\2</i>',  | 
        ||
| 223 | PointedEar | 142 | '/\\1',  | 
        
| 230 | PointedEar | 143 | '<em>\\1</em>',  | 
        
| 223 | PointedEar | 144 | ' ~',  | 
        
| 145 | ),  | 
        ||
| 224 | PointedEar | 146 | $matches['transl']);  | 
        
| 223 | PointedEar | 147 | |
| 148 | echo ($is_example ? "<i lang='$source_lang'>" : "<b lang='$source_lang'>")  | 
        ||
| 149 | . $phrase  | 
        ||
| 150 | . ($is_example ? '</i>' : '</b>')  | 
        ||
| 151 | . " <span lang='$target_lang'>" . $transl . '</span>';  | 
        ||
| 152 | |||
| 153 | $last_indent = $indent;  | 
        ||
| 154 |               } | 
        ||
| 155 |             } | 
        ||
| 156 |           } | 
        ||
| 230 | PointedEar | 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 | //           } | 
        ||
| 223 | PointedEar | 238 |         ?> | 
        
| 230 | PointedEar | 239 | <?php } ?>  | 
        
| 223 | PointedEar | 240 | </body>  | 
        
| 241 | </html>  |