| 1 |
<?php |
| 2 |
|
| 3 |
namespace Gettext\Languages\Exporter; |
| 4 |
|
| 5 |
class Html extends Exporter |
| 6 |
{ |
| 7 |
/** |
| 8 |
* {@inheritdoc} |
| 9 |
* |
| 10 |
* @see \Gettext\Languages\Exporter\Exporter::getDescription() |
| 11 |
*/ |
| 12 |
public static function getDescription() |
| 13 |
{ |
| 14 |
return 'Build a HTML table'; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* {@inheritdoc} |
| 19 |
* |
| 20 |
* @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
| 21 |
*/ |
| 22 |
protected static function toStringDo($languages) |
| 23 |
{ |
| 24 |
return self::buildTable($languages, false); |
| 25 |
} |
| 26 |
|
| 27 |
protected static function h($str) |
| 28 |
{ |
| 29 |
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
| 30 |
} |
| 31 |
|
| 32 |
protected static function buildTable($languages, $forDocs) |
| 33 |
{ |
| 34 |
$prefix = $forDocs ? ' ' : ''; |
| 35 |
$lines = array(); |
| 36 |
$lines[] = $prefix . '<table' . ($forDocs ? ' class="table table-bordered table-condensed table-striped"' : '') . '>'; |
| 37 |
$lines[] = $prefix . ' <thead>'; |
| 38 |
$lines[] = $prefix . ' <tr>'; |
| 39 |
$lines[] = $prefix . ' <th>Language code</th>'; |
| 40 |
$lines[] = $prefix . ' <th>Language name</th>'; |
| 41 |
$lines[] = $prefix . ' <th># plurals</th>'; |
| 42 |
$lines[] = $prefix . ' <th>Formula</th>'; |
| 43 |
$lines[] = $prefix . ' <th>Plurals</th>'; |
| 44 |
$lines[] = $prefix . ' </tr>'; |
| 45 |
$lines[] = $prefix . ' </thead>'; |
| 46 |
$lines[] = $prefix . ' <tbody>'; |
| 47 |
foreach ($languages as $lc) { |
| 48 |
$lines[] = $prefix . ' <tr>'; |
| 49 |
$lines[] = $prefix . ' <td>' . $lc->id . '</td>'; |
| 50 |
$name = self::h($lc->name); |
| 51 |
if (isset($lc->supersededBy)) { |
| 52 |
$name .= '<br /><small><span>Superseded by</span> ' . $lc->supersededBy . '</small>'; |
| 53 |
} |
| 54 |
$lines[] = $prefix . ' <td>' . $name . '</td>'; |
| 55 |
$lines[] = $prefix . ' <td>' . count($lc->categories) . '</td>'; |
| 56 |
$lines[] = $prefix . ' <td>' . self::h($lc->formula) . '</td>'; |
| 57 |
$cases = array(); |
| 58 |
foreach ($lc->categories as $c) { |
| 59 |
$cases[] = '<li><span>' . $c->id . '</span><code>' . self::h($c->examples) . '</code></li>'; |
| 60 |
} |
| 61 |
$lines[] = $prefix . ' <td><ol' . ($forDocs ? ' class="cases"' : '') . ' start="0">' . implode('', $cases) . '</ol></td>'; |
| 62 |
$lines[] = $prefix . ' </tr>'; |
| 63 |
} |
| 64 |
$lines[] = $prefix . ' </tbody>'; |
| 65 |
$lines[] = $prefix . '</table>'; |
| 66 |
|
| 67 |
return implode("\n", $lines); |
| 68 |
} |
| 69 |
} |
| 70 |
|