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