20 $pluralRule = GettextPlural::getPluralRule( $targetLanguage );
28 $expectedPluralCount = GettextPlural::getPluralCount( $pluralRule );
29 $definitionHasPlural = GettextPlural::hasPlural( $definition );
30 $translationHasPlural = GettextPlural::hasPlural( $translation );
32 $presence = $this->pluralPresenceCheck(
34 $translationHasPlural,
38 if ( $presence ===
'ok' ) {
39 [ $msgcode, $data ] = $this->pluralFormCountCheck( $translation, $expectedPluralCount );
40 if ( $msgcode ===
'invalid-count' ) {
44 'translate-checks-gettext-plural-count',
46 [
'COUNT', $expectedPluralCount ],
47 [
'COUNT', $data[
'count' ] ],
50 $issues->add( $issue );
52 } elseif ( $presence ===
'missing' ) {
56 'translate-checks-gettext-plural-missing'
58 $issues->add( $issue );
59 } elseif ( $presence ===
'unsupported' ) {
63 'translate-checks-gettext-plural-unsupported'
65 $issues->add( $issue );
72 private function pluralPresenceCheck(
74 $translationHasPlural,
77 if ( !$definitionHasPlural && $translationHasPlural ) {
79 } elseif ( $definitionHasPlural && !$translationHasPlural ) {
80 if ( $expectedPluralCount > 1 ) {
84 return 'not-applicable';
86 } elseif ( !$definitionHasPlural && !$translationHasPlural ) {
87 return 'not-applicable';
94 private function pluralFormCountCheck( $text, $expectedPluralCount ) {
95 [ , $instanceMap ] = GettextPlural::parsePluralForms( $text );
97 foreach ( $instanceMap as $forms ) {
98 $formsCount = count( $forms );
99 if ( $formsCount !== $expectedPluralCount ) {
100 return [
'invalid-count', [
'count' => $formsCount ] ];