r57299 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57298‎ | r57299 | r57300 >
Date:18:30, 2 October 2009
Author:siebrand
Status:deferred (Comments)
Tags:
Comment:
Update plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html. Complete per Date: 2009/05/12 11:24:52 for languages currently supported in MediaWiki.

Added FIXME where CLDR definition is different from MediaWiki's.
Modified paths:
  • /trunk/phase3/languages/classes/LanguageBe_tarask.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageBs.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageCy.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageGa.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageHr.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageLn.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageLv.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageMk.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageMo.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageRo.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageRu.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageSe.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageSh.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageSma.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageSr.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageUk.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/classes/LanguageHr.php
@@ -8,6 +8,8 @@
99
1010 function convertPlural( $count, $forms ) {
1111 if ( !count($forms) ) { return ''; }
 12+ // FIXME: CLDR defines 4 plural forms instead of 3. Plural for for decimals is missing.
 13+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
1214 $forms = $this->preConvertPlural( $forms, 3 );
1315
1416 if ($count > 10 && floor(($count % 100) / 10) == 1) {
Index: trunk/phase3/languages/classes/LanguageLn.php
@@ -0,0 +1,18 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageLn extends Language {
 8+ /**
 9+ * Use singular form for zero
 10+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ln
 11+
 12+ */
 13+ function convertPlural( $count, $forms ) {
 14+ if ( !count($forms) ) { return ''; }
 15+ $forms = $this->preConvertPlural( $forms, 2 );
 16+
 17+ return ($count <= 1) ? $forms[0] : $forms[1];
 18+ }
 19+}
Property changes on: trunk/phase3/languages/classes/LanguageLn.php
___________________________________________________________________
Added: svn:eol-style
120 + native
Added: svn:keywords
221 + Id
Index: trunk/phase3/languages/classes/LanguageLv.php
@@ -23,6 +23,9 @@
2424 */
2525 function convertPlural( $count, $forms ) {
2626 if ( !count($forms) ) { return ''; }
 27+
 28+ // FIXME: CLDR defines 3 plural forms instead of 2. Form for 0 is missing.
 29+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#lv
2730 $forms = $this->preConvertPlural( $forms, 2 );
2831
2932 return ( ( $count % 10 == 1 ) && ( $count % 100 != 11 ) ) ? $forms[0] : $forms[1];
Index: trunk/phase3/languages/classes/LanguageMk.php
@@ -0,0 +1,21 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageMk extends Language {
 8+ /**
 9+ * Plural forms per
 10+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mk
 11+ */
 12+ function convertPlural( $count, $forms ) {
 13+ if ( !count($forms) ) { return ''; }
 14+ $forms = $this->preConvertPlural( $forms, 2 );
 15+
 16+ if ($count > 10 && floor( ($count % 100 ) / 10 ) == 1 ) {
 17+ return $forms[1];
 18+ } else {
 19+ return $forms[0];
 20+ }
 21+ }
 22+}
Property changes on: trunk/phase3/languages/classes/LanguageMk.php
___________________________________________________________________
Added: svn:eol-style
123 + native
Added: svn:keywords
224 + Id
Index: trunk/phase3/languages/classes/LanguageMo.php
@@ -0,0 +1,23 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageMo extends Language {
 8+ function convertPlural( $count, $forms ) {
 9+ // Plural rules per
 10+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mo
 11+ if ( !count($forms) ) { return ''; }
 12+
 13+ $forms = $this->preConvertPlural( $forms, 3 );
 14+
 15+ if ( $count == 1 ) {
 16+ $index = 0;
 17+ } elseif ( $count == 0 || $count % 100 < 20 ) {
 18+ $index = 1;
 19+ } else {
 20+ $index = 2;
 21+ }
 22+ return $forms[$index];
 23+ }
 24+}
Property changes on: trunk/phase3/languages/classes/LanguageMo.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Added: svn:keywords
226 + Id
Index: trunk/phase3/languages/classes/LanguageUk.php
@@ -62,6 +62,8 @@
6363 //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
6464 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
6565
 66+ // FIXME: CLDR defines 4 plural forms. Form for decimals is missing/
 67+ // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#uk
6668 $forms = $this->preConvertPlural( $forms, 3 );
6769
6870 if ($count > 10 && floor(($count % 100) / 10) == 1) {
Index: trunk/phase3/languages/classes/LanguageBs.php
@@ -10,6 +10,8 @@
1111 if ( !count($forms) ) { return ''; }
1212 $forms = $this->preConvertPlural( $forms, 3 );
1313
 14+ // FIXME: CLDR defines 4 plural forms instead of 3. Plural for decimals is missing.
 15+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
1416 if ($count > 10 && floor(($count % 100) / 10) == 1) {
1517 return $forms[2];
1618 } else {
Index: trunk/phase3/languages/classes/LanguageRo.php
@@ -0,0 +1,23 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageRo extends Language {
 8+ function convertPlural( $count, $forms ) {
 9+ // Plural rules per
 10+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ro
 11+ if ( !count($forms) ) { return ''; }
 12+
 13+ $forms = $this->preConvertPlural( $forms, 3 );
 14+
 15+ if ( $count == 1 ) {
 16+ $index = 0;
 17+ } elseif ( $count == 0 || $count % 100 < 20 ) {
 18+ $index = 1;
 19+ } else {
 20+ $index = 2;
 21+ }
 22+ return $forms[$index];
 23+ }
 24+}
Property changes on: trunk/phase3/languages/classes/LanguageRo.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Added: svn:keywords
226 + Id
Index: trunk/phase3/languages/classes/LanguageSma.php
@@ -0,0 +1,22 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageSma extends Language {
 8+ function convertPlural( $count, $forms ) {
 9+ if ( !count($forms) ) { return ''; }
 10+
 11+ // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#sma
 12+ $forms = $this->preConvertPlural( $forms, 3 );
 13+
 14+ if ( $count == 1 ) {
 15+ $index = 1;
 16+ } elseif( $count == 2 ) {
 17+ $index = 2;
 18+ } else {
 19+ $index = 3;
 20+ }
 21+ return $forms[$index];
 22+ }
 23+}
Property changes on: trunk/phase3/languages/classes/LanguageSma.php
___________________________________________________________________
Added: svn:eol-style
124 + native
Added: svn:keywords
225 + Id
Index: trunk/phase3/languages/classes/LanguageRu.php
@@ -76,6 +76,8 @@
7777 //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
7878 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
7979
 80+ // FIXME: CLDR defines 4 plural forms. Form with decimals missing.
 81+ // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru
8082 $forms = $this->preConvertPlural( $forms, 3 );
8183
8284 if ($count > 10 && floor(($count % 100) / 10) == 1) {
Index: trunk/phase3/languages/classes/LanguageGa.php
@@ -34,4 +34,20 @@
3535 }
3636 return $word;
3737 }
 38+
 39+ function convertPlural( $count, $forms ) {
 40+ if ( !count($forms) ) { return ''; }
 41+
 42+ // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ga
 43+ $forms = $this->preConvertPlural( $forms, 3 );
 44+
 45+ if ( $count == 1 ) {
 46+ $index = 1;
 47+ } elseif( $count == 2 ) {
 48+ $index = 2;
 49+ } else {
 50+ $index = 3;
 51+ }
 52+ return $forms[$index];
 53+ }
3854 }
Index: trunk/phase3/languages/classes/LanguageBe_tarask.php
@@ -25,6 +25,8 @@
2626 //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
2727 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
2828
 29+ // FIXME: CLDR defines 4 plural forms instead of 3
 30+ // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
2931 $forms = $this->preConvertPlural( $forms, 3 );
3032
3133 if ($count > 10 && floor(($count % 100) / 10) == 1) {
Index: trunk/phase3/languages/classes/LanguageSe.php
@@ -0,0 +1,22 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageSe extends Language {
 8+ function convertPlural( $count, $forms ) {
 9+ if ( !count($forms) ) { return ''; }
 10+
 11+ // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#se
 12+ $forms = $this->preConvertPlural( $forms, 3 );
 13+
 14+ if ( $count == 1 ) {
 15+ $index = 1;
 16+ } elseif( $count == 2 ) {
 17+ $index = 2;
 18+ } else {
 19+ $index = 3;
 20+ }
 21+ return $forms[$index];
 22+ }
 23+}
Property changes on: trunk/phase3/languages/classes/LanguageSe.php
___________________________________________________________________
Added: svn:eol-style
124 + native
Added: svn:keywords
225 + Id
Index: trunk/phase3/languages/classes/LanguageSh.php
@@ -0,0 +1,29 @@
 2+<?php
 3+/**
 4+ *
 5+ * @ingroup Language
 6+ */
 7+class LanguageSh extends Language {
 8+ function convertPlural( $count, $forms ) {
 9+ if ( !count($forms) ) { return ''; }
 10+
 11+ //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
 12+ if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
 13+
 14+ // FIXME: CLDR defines 4 plural forms. Form with decimals missing.
 15+ // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#sh
 16+ $forms = $this->preConvertPlural( $forms, 3 );
 17+
 18+ if ($count > 10 && floor(($count % 100) / 10) == 1) {
 19+ return $forms[2];
 20+ } else {
 21+ switch ($count % 10) {
 22+ case 1: return $forms[0];
 23+ case 2:
 24+ case 3:
 25+ case 4: return $forms[1];
 26+ default: return $forms[2];
 27+ }
 28+ }
 29+ }
 30+}
Property changes on: trunk/phase3/languages/classes/LanguageSh.php
___________________________________________________________________
Added: svn:eol-style
131 + native
Added: svn:keywords
232 + Id
Index: trunk/phase3/languages/classes/LanguageCy.php
@@ -8,6 +8,9 @@
99 class LanguageCy extends Language {
1010 function convertPlural( $count, $forms ) {
1111 if ( !count($forms) ) { return ''; }
 12+
 13+ // FIXME: CLDR defines 4 plural forms; very different, actually.
 14+ // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#cy
1215 $forms = $this->preConvertPlural( $forms, 6 );
1316 $count = abs( $count );
1417 if ( $count >= 0 && $count <= 3 ) {
Index: trunk/phase3/languages/classes/LanguageSr.php
@@ -183,4 +183,27 @@
184184 $this->mConverter = new SrConverter($this, 'sr', $variants, $variantfallbacks, $marker, $flags);
185185 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
186186 }
 187+
 188+ function convertPlural( $count, $forms ) {
 189+ if ( !count($forms) ) { return ''; }
 190+
 191+ //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
 192+ if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
 193+
 194+ // FIXME: CLDR defines 4 plural forms. Form with decimals missing.
 195+ // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru
 196+ $forms = $this->preConvertPlural( $forms, 3 );
 197+
 198+ if ($count > 10 && floor(($count % 100) / 10) == 1) {
 199+ return $forms[2];
 200+ } else {
 201+ switch ($count % 10) {
 202+ case 1: return $forms[0];
 203+ case 2:
 204+ case 3:
 205+ case 4: return $forms[1];
 206+ default: return $forms[2];
 207+ }
 208+ }
 209+ }
187210 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r57476Fix for r57299: index starts with 0, not 1 :)ialex18:37, 7 October 2009

Comments

#Comment by Verdy p (talk | contribs)   21:24, 9 November 2009

French plural still not correct. Replace:

 return ($count <= 1) ? $forms[0] : $forms[1];

by

 return ($count < 2) ? $forms[0] : $forms[1];

Note that in French « 1,25 heure » is still singular (like also zero, or fractions lower than unity), not plural that starts only at 2, but not 2 minus a fraction of unity. It's opposed to « 2 heures » (plural).

See CLDR report which states the same thing:

 one → n within 0..2 and n is not 2;
 other → everything else.

Note that the sign should also be ignored, i.e. only the absolute value is significant (I think this is assumed in the CLDR plurals report that it just suppose that n cannot be negative). If you need to take it into account, then the CLDR-equivalent rule for French is:

 one → (n within -2..2) and (n is not 2) and (n is not -2);
 other → everything else.

or in a single PHP expression:

 return $forms[fabs($count) < 2];

Status & tagging log