Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
ReplacementValidator.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Validation\Validators;
5
6use InvalidArgumentException;
11
18 private $search;
19 private $replace;
20
21 public function __construct( array $params ) {
22 $this->search = $params['search'] ?? null;
23 $this->replace = $params['replace'] ?? null;
24 if ( !is_string( $this->search ) ) {
25 throw new InvalidArgumentException( '`search` is not a string' );
26 }
27
28 if ( !is_string( $this->replace ) ) {
29 throw new InvalidArgumentException( '`replace` is not a string' );
30 }
31 }
32
33 public function getIssues( Message $message, string $targetLanguage ): ValidationIssues {
34 $issues = new ValidationIssues();
35
36 if ( str_contains( $message->translation(), $this->search ) ) {
37 $issue = new ValidationIssue(
38 'replacement',
39 'replacement',
40 'translate-checks-replacement',
41 [
42 [ 'PLAIN', $this->search ],
43 [ 'PLAIN', $this->replace ],
44 ]
45 );
46
47 $issues->add( $issue );
48 }
49
50 return $issues;
51 }
52}
Interface for message objects used by MessageCollection.
Definition Message.php:13