Rev 224 |
Rev 232 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
1
<!DOCTYPE html>
<html lang="en"">
<head>
<meta charset="UTF-8">
<title>Modern Golic Vulcan – Federation Standard English Dictionary</title>
<style type="text/css">
body {
font-family: serif;
}
ol
{
padding-left: 0;
list-style-type: none;
}
ol li
{
margin-left: 0;
}
ol ol
{
padding-left: 1em;
}
.type-or-context {
font-family: sans-serif;
font-size: small;
font-weight: bold;
}
i em {
font-weight: bold;
}
</style>
</head>
<body>
<?php
$source_lang = 'vuh-Latn-Gol-modern';
$target_lang = 'en-Latn-Federation';
$lines = file('vul-gol-en.dict');
?>
<h1>Modern Golic Vulcan – Federation Standard English Dictionary</h1>
<?php
define('REGEXP_PREFIX_EXAMPLE', '/^ex\s*=\s*/');
if ($lines)
{
$last_indent = -1;
$last_phrases = array();
foreach ($lines as $line)
{
preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches);
// var_dump($matches);
if ($matches)
{
$phrase = $matches['phrase'];
if (mb_strpos($phrase, '#') === false)
{
$indent = mb_strlen($matches['lws']) / 2;
if ($indent > $last_indent)
{
echo '<ol>';
}
else
{
echo str_repeat('</ol>', $last_indent - $indent);
}
echo '<li>';
$is_example = preg_match(REGEXP_PREFIX_EXAMPLE
, $phrase);
if ($is_example)
{
$phrase = preg_replace(REGEXP_PREFIX_EXAMPLE
, '', $phrase);
}
if ($indent > $last_indent)
{
$last_phrases[] = $phrase;
}
else if ($indent < $last_indent)
{
$last_phrases = array_slice($last_phrases, 0, $indent + 1);
}
if ($indent <= $last_indent)
{
$last_phrases[count($last_phrases) - 1] = $phrase;
}
$phrase = preg_replace(
array(
'/~/',
'/[()]/',
),
array(
'=',
'|',
),
$phrase);
if ($last_phrases)
{
end($last_phrases);
while (($last_phrase = prev($last_phrases)) !== false)
{
while (mb_strlen($last_phrase) > 1)
{
if (preg_match('/' . preg_quote($last_phrase) . '/i',
$phrase, $last_sub_matches))
{
$phrase = preg_replace('/' . $last_sub_matches[0] . '/i',
'<u>\\0</u>', $phrase);
break 2;
}
$last_phrase = mb_strcut($last_phrase, 0, mb_strlen($last_phrase) - 1);
}
}
}
$transl = preg_replace(
array(
'/"([^"]+)"/',
'/\{([^\}]+)\}/',
'/(^|[\\s+\\[])\\/([\\s\\w\'()-]+)\\/(?=[,.;:\\s+\\]]|$)/u',
'/\|(.*)(?<!\|)/',
'/\*(.+?)\*/',
'/\\s+~/',
),
array(
'“\\1”',
'<abbr class="type-or-context" lang="' . $target_lang . '">\\1</abbr>',
'\\1<i lang="' . $source_lang . '">\\2</i>',
'/\\1',
'<em>\\1</em>',
' ~',
),
$matches['transl']);
echo ($is_example ?
"<i lang='$source_lang'>" : "<b lang='$source_lang'>")
. $phrase
. ($is_example ?
'</i>' : '</b>')
. " <span lang='$target_lang'>" . $transl . '</span>';
$last_indent = $indent;
}
}
}
echo '</ol>';
// $phrases = array();
// foreach ($lines as $line)
// {
// preg_match('/^(?<lws>\s*)(?<phrase>[^:]+)\s*:\s*(?<transl>.+)/u', $line, $matches);
// if ($matches)
// {
// $phrase = $matches['phrase'];
// /* if not a comment */
// if (mb_strpos($phrase, '#') === false)
// {
// $transl = $matches['transl'];
// $is_example = preg_match(REGEXP_PREFIX_EXAMPLE, $phrase);
// if ($is_example)
// {
// /* assign example to previous phrase; indentation irrelevant */
// $phrase = preg_replace(REGEXP_PREFIX_EXAMPLE, '', $phrase);
// $prev_phrase['examples'][$phrase] = $transl;
// }
// else
// {
// /* create new phrase */
// $level = mb_strlen($matches['lws']) / 2;
// $phrases[$phrase] = array(
// 'translation' => $transl,
// 'level' => $level
// );
// $prev_phrase =& $phrases[$phrase];
// }
// }
// }
// }
// // var_dump($phrases);
// if ($phrases)
// {
// $prev_level = -1;
// foreach ($phrases as $phrase => $data)
// {
// $level = $data['level'];
// if ($level > $prev_level)
// {
// echo "\n<ol>\n";
// }
// else if ($level < $prev_level)
// {
// echo str_repeat("</ol>\n", $prev_level - $level);
// }
// $translation = $data['translation'];
// echo "\n<li>$prev_level => $level <b lang='$source_lang'>" . htmlspecialchars($phrase) . '</b>'
// . " <span lang='$target_lang'>" . $translation . '</span>';
// if (isset($data['examples']))
// {
// echo '<ul>';
// foreach ($data['examples'] as $original => $translation)
// {
// echo "<li><i lang='$source_lang'>" . htmlspecialchars($original) . '</i>'
// . " <span lang='$target_lang'>" . $translation . '</span></li>';
// }
// echo '</ul>';
// }
// $prev_level = $level;
// }
// echo '</ol>';
// }
?>
<?php } ?>
</body>
</html>