Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWikiTimeListValidator.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Validation\Validators;
5
9use TMessage;
10
19 public function getIssues( TMessage $message, string $targetLanguage ): ValidationIssues {
20 $issues = new ValidationIssues();
21
22 $definition = $message->definition();
23 $translation = $message->translation();
24 $defArray = explode( ',', $definition );
25 $traArray = explode( ',', $translation );
26
27 $defCount = count( $defArray );
28 $traCount = count( $traArray );
29 if ( $defCount !== $traCount ) {
30 $issue = new ValidationIssue(
31 'miscmw',
32 'timelist-count',
33 'translate-checks-format',
34 [
35 [
36 'MESSAGE',
37 [
38 'translate-checks-parametersnotequal',
39 [ 'COUNT', $traCount ],
40 [ 'COUNT', $defCount ],
41 ]
42 ]
43 ]
44 );
45 $issues->add( $issue );
46
47 return $issues;
48 }
49
50 for ( $i = 0; $i < $defCount; $i++ ) {
51 $defItems = array_map( 'trim', explode( ':', $defArray[$i] ) );
52 $traItems = array_map( 'trim', explode( ':', $traArray[$i] ) );
53
54 if ( count( $traItems ) !== 2 ) {
55 $issue = new ValidationIssue(
56 'miscmw',
57 'timelist-format',
58 'translate-checks-format',
59 [ [ 'MESSAGE', [ 'translate-checks-malformed', $traArray[$i] ] ] ]
60 );
61
62 $issues->add( $issue );
63 continue;
64 }
65
66 if ( $traItems[1] !== $defItems[1] ) {
67 $issue = new ValidationIssue(
68 'miscmw',
69 'timelist-format-value',
70 'translate-checks-format',
71 // FIXME: i18n missing.
72 [ "<samp><nowiki>$traItems[1] !== $defItems[1]</nowiki></samp>" ]
73 );
74
75 $issues->add( $issue );
76 }
77 }
78
79 return $issues;
80 }
81}
Interface for message objects used by MessageCollection.
Definition Message.php:14
definition()
Get the message definition.
Definition Message.php:51
translation()
Get the message translation.