Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
GettextNewlineValidator.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Validation\Validators;
5
7use TMessage;
8
18 public function getIssues( TMessage $message, string $targetLanguage ): ValidationIssues {
19 $translation = $message->translation();
20 $definition = $message->definition();
21
22 // ending newlines in GetText are bounded by a "\"
23 $definition = $this->removeTrailingSlash( $definition );
24 $translation = $this->removeTrailingSlash( $translation );
25
26 $definitionStartNewline = $this->getStartingNewLinesCount( $definition );
27 $definitionEndNewline = $this->getEndingNewLineCount( $definition );
28
29 $translationStartNewline = $this->getStartingNewLinesCount( $translation );
30 $translationEndNewline = $this->getEndingNewLineCount( $translation );
31
32 $failingChecks = array_merge(
33 $this->validateStartingNewline( $definitionStartNewline, $translationStartNewline ),
34 $this->validateEndingNewline( $definitionEndNewline, $translationEndNewline )
35 );
36
37 return $this->createIssues( $failingChecks );
38 }
39
40 private function removeTrailingSlash( string $str ): string {
41 if ( substr( $str, -strlen( '\\' ) ) === '\\' ) {
42 return substr( $str, 0, -1 );
43 }
44
45 return $str;
46 }
47}
Ensures that the translation has the same number of newlines as the source message at the beginning a...
Ensures that the translation has the same number of newlines as the source message at the beginning o...
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.