New magic word: PLURALFORM (like GRAMMAR)
authorAlexander Sigachov <ajvol@users.mediawiki.org>
Mon, 5 Sep 2005 19:22:09 +0000 (19:22 +0000)
committerAlexander Sigachov <ajvol@users.mediawiki.org>
Mon, 5 Sep 2005 19:22:09 +0000 (19:22 +0000)
includes/MagicWord.php
includes/Parser.php
languages/Language.php
languages/LanguageRu.php

index a0825ee..db34f25 100644 (file)
@@ -56,6 +56,7 @@ define('MAG_SCRIPTPATH',              41);
 define('MAG_SERVERNAME',               42);
 define('MAG_NUMBEROFFILES',            43);
 define('MAG_IMG_MANUALTHUMB',          44);
+define('MAG_PLURALFORM',               45);
 
 $wgVariableIDs = array(
        MAG_CURRENTMONTH,
index 9a1ae42..1914613 100644 (file)
@@ -2174,6 +2174,16 @@ class Parser
                        }
                }
 
+               # PLURALFORM
+               if ( !$found && $argc >= 2 ) {
+                       $mwPluralForm =& MagicWord::get( MAG_PLURALFORM );
+                       if ( $mwPluralForm->matchStartAndRemove( $part1 ) ) {
+                               if ($argc==2) {$args[2]=$args[1];}
+                               $text = $linestart . $wgContLang->convertPluralForm( $part1, $args[0], $args[1], $args[2]);
+                               $found = true;
+                       }
+               }
+
                # Template table test
 
                # Did we encounter this template already? If yes, it is in the cache
index 673076d..f025d7c 100644 (file)
@@ -2782,6 +2782,28 @@ class Language {
                return $word;
        }
 
+       /**
+        * Plural form transformations, needed for some languages.
+        * For example, where are 3 form of plural in Russian and Polish,
+        * depending on "count mod 10". See [[w:Plural]]
+        * For English it is pretty simple.
+        *
+        * Invoked by putting {{pluralform:count|wordform1|wordform2}}
+        * or {{pluralform:count|wordform1|wordform2|wordform3}}
+        *
+        * Example: {{pluralform:{{NUMBEROFARTICLES}}|article|articles}} 
+        *
+        * @param string $count
+        * @param string $wordform1
+        * @param string $wordform2
+        * @param string $wordform3 (optional)
+        * @return string
+        */
+       function convertPluralForm( $count, $wordform1, $wordform2, $wordform3) {
+               if ($count==1) {return $wordform1;}
+               else {return $wordform2;}
+       }
+
        /**
         * For translaing of expiry times
         * @param string The validated block time in English
index 5ceb6f0..2454cca 100644 (file)
@@ -2000,6 +2000,21 @@ class LanguageRu extends LanguageUtf8 {
                return $word;
        }
 
+       function convertPluralForm( $count, $wordform1, $wordform2, $wordform3) {
+               if ($count > 10 && floor(($count % 100) / 10) == 1) {
+                       return $wordform3;
+               }
+               else {
+                       switch ($count % 10) {
+                               case 1: return $wordform1;
+                               case 2: return $wordform2;
+                               case 3: return $wordform2;
+                               case 4: return $wordform2;
+                               default: return $wordform3;
+                       }
+               }
+       }
+
        function formatNum( $number ) {
                global $wgTranslateNumerals;
                return $wgTranslateNumerals ? strtr($number, '.,', ', ' ) : $number;