Rev 223 | 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">  | 
        ||
| 5 | <title>Modern Golic Vulcan – Federation Standard English Dictionary</title>  | 
        ||
| 6 | <style type="text/css">  | 
        ||
| 7 |       ol { | 
        ||
| 8 | padding-left: 0;  | 
        ||
| 9 | list-style-type: none;  | 
        ||
| 10 | }  | 
        ||
| 11 | |||
| 12 |       ol li { | 
        ||
| 13 | margin-left: 0;  | 
        ||
| 14 | }  | 
        ||
| 15 | |||
| 16 |       ol ol { | 
        ||
| 17 | padding-left: 1em;  | 
        ||
| 18 | }  | 
        ||
| 19 | </style>  | 
        ||
| 20 | </head>  | 
        ||
| 21 | |||
| 22 | <body>  | 
        ||
| 23 | <h1>Modern Golic Vulcan – Federation Standard English Dictionary</h1>  | 
        ||
| 24 |       <?php | 
        ||
| 25 | define('REGEXP_PREFIX_EXAMPLE', '/^ex\s*=\s*/');  | 
        ||
| 26 | |||
| 27 | $source_lang = 'vuh-Latn-Gol-modern';  | 
        ||
| 28 | $target_lang = 'en-Latn-Federation';  | 
        ||
| 29 | $lines = file('vul-gol-en.dict');  | 
        ||
| 30 | |||
| 31 | if ($lines)  | 
        ||
| 32 |         { | 
        ||
| 33 | $last_indent = -1;  | 
        ||
| 34 | $last_phrases = array();  | 
        ||
| 35 | |||
| 36 | foreach ($lines as $line)  | 
        ||
| 37 |           { | 
        ||
| 38 | preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches);  | 
        ||
| 39 | // var_dump($matches); | 
        ||
| 40 | if ($matches)  | 
        ||
| 41 |             { | 
        ||
| 42 | $phrase = $matches['phrase'];  | 
        ||
| 43 | |||
| 44 | if (mb_strpos($phrase, '#') === false)  | 
        ||
| 45 |               { | 
        ||
| 46 | $indent = mb_strlen($matches['lws']) / 2;  | 
        ||
| 47 | |||
| 48 | if ($indent > $last_indent)  | 
        ||
| 49 |                 { | 
        ||
| 50 | echo '<ol>';  | 
        ||
| 51 |                 } | 
        ||
| 52 |                 else | 
        ||
| 53 |                 { | 
        ||
| 54 | echo str_repeat('</ol>', $last_indent - $indent);  | 
        ||
| 55 |                 } | 
        ||
| 56 | |||
| 57 | echo '<li>';  | 
        ||
| 58 | |||
| 59 | $is_example = preg_match(REGEXP_PREFIX_EXAMPLE, $phrase);  | 
        ||
| 60 | if ($is_example)  | 
        ||
| 61 |                 { | 
        ||
| 62 | $phrase = preg_replace(REGEXP_PREFIX_EXAMPLE, '', $phrase);  | 
        ||
| 63 |                 } | 
        ||
| 64 | |||
| 65 | if ($indent > $last_indent)  | 
        ||
| 66 |                 { | 
        ||
| 67 | $last_phrases[] = $phrase;  | 
        ||
| 68 |                 } | 
        ||
| 69 | else if ($indent < $last_indent)  | 
        ||
| 70 |                 { | 
        ||
| 71 | $last_phrases = array_slice($last_phrases, 0, $indent + 1);  | 
        ||
| 72 |                 } | 
        ||
| 73 | |||
| 74 | if ($indent <= $last_indent)  | 
        ||
| 75 |                 { | 
        ||
| 76 | $last_phrases[count($last_phrases) - 1] = $phrase;  | 
        ||
| 77 |                 } | 
        ||
| 78 | |||
| 79 | $phrase = preg_replace(  | 
        ||
| 80 | array(  | 
        ||
| 81 | '/~/',  | 
        ||
| 82 | '/[()]/',  | 
        ||
| 83 | ),  | 
        ||
| 84 | array(  | 
        ||
| 85 | '=',  | 
        ||
| 86 | '|',  | 
        ||
| 87 | ),  | 
        ||
| 88 | $phrase);  | 
        ||
| 89 | |||
| 90 | if ($last_phrases)  | 
        ||
| 91 |                 { | 
        ||
| 92 | end($last_phrases);  | 
        ||
| 93 | |||
| 94 | while (($last_phrase = prev($last_phrases)) !== false)  | 
        ||
| 95 |                   { | 
        ||
| 96 | while (mb_strlen($last_phrase) > 1)  | 
        ||
| 97 |                     { | 
        ||
| 98 | if (preg_match('/' . preg_quote($last_phrase) . '/i',  | 
        ||
| 99 | $phrase, $last_sub_matches))  | 
        ||
| 100 |                       { | 
        ||
| 101 | $phrase = preg_replace('/' . $last_sub_matches[0] . '/i',  | 
        ||
| 102 | '<u>\\0</u>', $phrase);  | 
        ||
| 103 | break 2;  | 
        ||
| 104 |                       } | 
        ||
| 105 | |||
| 106 | $last_phrase = mb_strcut($last_phrase, 0, mb_strlen($last_phrase) - 1);  | 
        ||
| 107 |                     } | 
        ||
| 108 |                   } | 
        ||
| 109 |                 } | 
        ||
| 110 | |||
| 111 | $transl = preg_replace(  | 
        ||
| 112 | array(  | 
        ||
| 113 | '/"([^"]+)"/',  | 
        ||
| 114 | '/\\/([\\s\\w\'()-]+)\\//u',  | 
        ||
| 115 | '/\|(.*)(?<!\|)/',  | 
        ||
| 116 | '/\\s+~/',  | 
        ||
| 117 | ),  | 
        ||
| 118 | array(  | 
        ||
| 119 | '“\\1”',  | 
        ||
| 120 | '<i lang="' . $source_lang . '">\\1</i>',  | 
        ||
| 121 | '/\\1',  | 
        ||
| 122 | ' ~',  | 
        ||
| 123 | ),  | 
        ||
| 224 | PointedEar | 124 | $matches['transl']);  | 
        
| 223 | PointedEar | 125 | |
| 126 | echo ($is_example ? "<i lang='$source_lang'>" : "<b lang='$source_lang'>")  | 
        ||
| 127 | . $phrase  | 
        ||
| 128 | . ($is_example ? '</i>' : '</b>')  | 
        ||
| 129 | . " <span lang='$target_lang'>" . $transl . '</span>';  | 
        ||
| 130 | |||
| 131 | $last_indent = $indent;  | 
        ||
| 132 |               } | 
        ||
| 133 |             } | 
        ||
| 134 |           } | 
        ||
| 135 |         ?> | 
        ||
| 136 | </ol>  | 
        ||
| 137 | <?php } ?>  | 
        ||
| 138 | </body>  | 
        ||
| 139 | </html>  |