Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
MediaWikiPageNameValidator | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
getIssues | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Validation\Validators; |
5 | |
6 | use MediaWiki\Extension\Translate\MessageLoading\Message; |
7 | use MediaWiki\Extension\Translate\Validation\MessageValidator; |
8 | use MediaWiki\Extension\Translate\Validation\ValidationIssue; |
9 | use MediaWiki\Extension\Translate\Validation\ValidationIssues; |
10 | |
11 | /** |
12 | * Ensures that translations do not translate namespaces. |
13 | * @author Abijeet Patro |
14 | * @license GPL-2.0-or-later |
15 | * @since 2020.02 |
16 | */ |
17 | class MediaWikiPageNameValidator implements MessageValidator { |
18 | public function getIssues( Message $message, string $targetLanguage ): ValidationIssues { |
19 | $issues = new ValidationIssues(); |
20 | |
21 | $definition = $message->definition(); |
22 | $translation = $message->translation(); |
23 | |
24 | $namespaces = 'help|project|\{\{ns:project}}|mediawiki'; |
25 | $matches = []; |
26 | if ( preg_match( "/^($namespaces):[\w\s]+$/ui", $definition, $matches ) && |
27 | !preg_match( "/^{$matches[1]}:.+$/u", $translation ) |
28 | ) { |
29 | $issue = new ValidationIssue( |
30 | 'pagename', |
31 | 'namespace', |
32 | 'translate-checks-pagename' |
33 | ); |
34 | $issues->add( $issue ); |
35 | } |
36 | |
37 | return $issues; |
38 | } |
39 | } |