Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
I18n | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
run | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Wt2Html\PP\Processors; |
5 | |
6 | use Wikimedia\Parsoid\Config\Env; |
7 | use Wikimedia\Parsoid\DOM\Element; |
8 | use Wikimedia\Parsoid\DOM\Node; |
9 | use Wikimedia\Parsoid\Utils\DOMCompat; |
10 | use Wikimedia\Parsoid\Utils\DOMDataUtils; |
11 | use Wikimedia\Parsoid\Utils\DOMUtils; |
12 | use Wikimedia\Parsoid\Wt2Html\Wt2HtmlDOMProcessor; |
13 | |
14 | /** This pass adds placeholders for i18n messages. It will eventually be replaced by a HTML2HTML pass in core. */ |
15 | class I18n implements Wt2HtmlDOMProcessor { |
16 | |
17 | /** |
18 | * @inheritDoc |
19 | */ |
20 | public function run( |
21 | Env $env, Node $root, array $options = [], bool $atTopLevel = false |
22 | ): void { |
23 | '@phan-var Element|DocumentFragment $root'; // @var Element|DocumentFragment $root |
24 | $spans = DOMCompat::querySelectorAll( $root, 'span[typeof~="mw:I18n"]' ); |
25 | foreach ( $spans as $span ) { |
26 | DOMUtils::removeTypeOf( $span, 'mw:I18n' ); |
27 | $i18n = DOMDataUtils::getDataNodeI18n( $span ); |
28 | $span->appendChild( |
29 | $span->ownerDocument->createTextNode( $i18n->key ) |
30 | ); |
31 | } |
32 | } |
33 | |
34 | } |