From b7b513f611a24c5b27f81c1e971005be57f74ce4 Mon Sep 17 00:00:00 2001 From: Alexander Sigachov Date: Mon, 5 Sep 2005 19:22:09 +0000 Subject: [PATCH] New magic word: PLURALFORM (like GRAMMAR) --- includes/MagicWord.php | 1 + includes/Parser.php | 10 ++++++++++ languages/Language.php | 22 ++++++++++++++++++++++ languages/LanguageRu.php | 15 +++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/includes/MagicWord.php b/includes/MagicWord.php index a0825ee6e3..db34f25f5d 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -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, diff --git a/includes/Parser.php b/includes/Parser.php index 9a1ae42750..1914613a71 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 diff --git a/languages/Language.php b/languages/Language.php index 673076d3b7..f025d7c8c8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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 diff --git a/languages/LanguageRu.php b/languages/LanguageRu.php index 5ceb6f081f..2454cca1cf 100644 --- a/languages/LanguageRu.php +++ b/languages/LanguageRu.php @@ -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; -- 2.20.1