| 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::toStringDoWithOptions() |
| 21 |
*/ |
| 22 |
protected static function toStringDoWithOptions($languages, array $options) |
| 23 |
{ |
| 24 |
$lines = array(); |
| 25 |
$lines[] = '<table>'; |
| 26 |
$lines[] = ' <thead>'; |
| 27 |
$lines[] = ' <tr>'; |
| 28 |
$lines[] = ' <th>Language code</th>'; |
| 29 |
$lines[] = ' <th>Language name</th>'; |
| 30 |
$lines[] = ' <th># plurals</th>'; |
| 31 |
$lines[] = ' <th>Formula</th>'; |
| 32 |
$lines[] = ' <th>Plurals</th>'; |
| 33 |
$lines[] = ' </tr>'; |
| 34 |
$lines[] = ' </thead>'; |
| 35 |
$lines[] = ' <tbody>'; |
| 36 |
foreach ($languages as $lc) { |
| 37 |
$lines[] = ' <tr>'; |
| 38 |
$lines[] = ' <td>' . $lc->id . '</td>'; |
| 39 |
$name = self::h($lc->name); |
| 40 |
if (isset($lc->supersededBy)) { |
| 41 |
$name .= '<br /><small><span>Superseded by</span> ' . $lc->supersededBy . '</small>'; |
| 42 |
} |
| 43 |
$lines[] = ' <td>' . $name . '</td>'; |
| 44 |
$lines[] = ' <td>' . count($lc->categories) . '</td>'; |
| 45 |
$lines[] = ' <td>' . self::h($lc->formula) . '</td>'; |
| 46 |
$cases = array(); |
| 47 |
foreach ($lc->categories as $c) { |
| 48 |
$cases[] = '<li><span>' . $c->id . '</span><code>' . self::h($c->examples) . '</code></li>'; |
| 49 |
} |
| 50 |
$lines[] = ' <td><ol start="0">' . implode('', $cases) . '</ol></td>'; |
| 51 |
$lines[] = ' </tr>'; |
| 52 |
} |
| 53 |
$lines[] = ' </tbody>'; |
| 54 |
$lines[] = '</table>'; |
| 55 |
|
| 56 |
return implode("\n", $lines); |
| 57 |
} |
| 58 |
|
| 59 |
protected static function h($str) |
| 60 |
{ |
| 61 |
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
| 62 |
} |
| 63 |
} |
| 64 |
|