Subversion Repositories LCARS

Compare Revisions

Last modification

Ignore whitespace Rev 222 → Rev 223

/trunk/tools/eazytrans/vul-gol-en.php
0,0 → 1,139
<!DOCTYPE html>
<html lang="en"">
<head>
<meta charset="UTF-8">
<title>Modern Golic Vulcan – Federation Standard English Dictionary</title>
<style type="text/css">
ol {
padding-left: 0;
list-style-type: none;
}
 
ol li {
margin-left: 0;
}
 
ol ol {
padding-left: 1em;
}
</style>
</head>
 
<body>
<h1>Modern Golic Vulcan – Federation Standard English Dictionary</h1>
<?php
define('REGEXP_PREFIX_EXAMPLE', '/^ex\s*=\s*/');
 
$source_lang = 'vuh-Latn-Gol-modern';
$target_lang = 'en-Latn-Federation';
$lines = file('vul-gol-en.dict');
 
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\\w\'()-]+)\\//u',
'/\|(.*)(?<!\|)/',
'/\\s+~/',
),
array(
'“\\1”',
'<i lang="' . $source_lang . '">\\1</i>',
'/\\1',
'&nbsp;~',
),
strip_tags($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;
}
}
}
?>
</ol>
<?php } ?>
</body>
</html>