24 $expectedKeywords = UnicodePlural::getPluralKeywords( $targetLanguage );
26 if ( $expectedKeywords ===
null ) {
32 $definitionHasPlural = UnicodePlural::hasPlural( $definition );
33 $translationHasPlural = UnicodePlural::hasPlural( $translation );
35 $presence = $this->pluralPresenceCheck(
41 if ( $presence ===
'missing' ) {
42 $issue =
new ValidationIssue(
'plural',
'missing',
'translate-checks-unicode-plural-missing' );
43 $issues->add( $issue );
44 } elseif ( $presence ===
'unsupported' ) {
45 $issue =
new ValidationIssue(
'plural',
'unsupported',
'translate-checks-unicode-plural-unsupported' );
46 $issues->add( $issue );
47 } elseif ( $presence ===
'ok' ) {
48 [ $msgcode, $actualKeywords ] =
49 $this->pluralFormCheck( $translation, $expectedKeywords );
50 if ( $msgcode ===
'invalid' ) {
51 $expectedExample = UnicodePlural::flattenList(
52 array_map( [ $this,
'createFormExample' ], $expectedKeywords )
54 $actualExample = UnicodePlural::flattenList(
55 array_map( [ $this,
'createFormExample' ], $actualKeywords )
61 'translate-checks-unicode-plural-invalid',
63 [
'PLAIN', $expectedExample ],
64 [
'PLAIN', $actualExample ],
67 $issues->add( $issue );
74 private function createFormExample(
string $keyword ): array {
75 return [ $keyword,
'…' ];
78 private function pluralPresenceCheck(
79 bool $definitionHasPlural,
80 bool $translationHasPlural
82 if ( !$definitionHasPlural && $translationHasPlural ) {
84 } elseif ( $definitionHasPlural && !$translationHasPlural ) {
86 } elseif ( !$definitionHasPlural && !$translationHasPlural ) {
87 return 'not-applicable';
94 private function pluralFormCheck(
string $text, array $expectedKeywords ): array {
95 [ , $instanceMap ] = UnicodePlural::parsePluralForms( $text );
97 foreach ( $instanceMap as $forms ) {
99 foreach ( $forms as [ $keyword, ] ) {
100 $actualKeywords[] = $keyword;
103 if ( $actualKeywords !== $expectedKeywords ) {
104 return [
'invalid', $actualKeywords ];