Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.960.2.15 diff -u -r1.960.2.15 moodlelib.php --- lib/moodlelib.php 4 Dec 2007 11:46:12 -0000 1.960.2.15 +++ lib/moodlelib.php 4 Dec 2007 13:57:03 -0000 @@ -5019,7 +5019,7 @@ foreach ($locations as $location) { $locallangfile = $location.$lang.'_local'.'/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5027,7 +5027,7 @@ //if local directory not found, or particular string does not exist in local direcotry $langfile = $location.$lang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5045,14 +5045,14 @@ foreach ($locations as $location) { $langfile = $location.$lang.'/'.$filetocheck; if (file_exists($langfile)) { - if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang")) { + if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang", $a)) { eval($result); if (!empty($parentlang)) { // found it! //first, see if there's a local file for parent $locallangfile = $location.$parentlang.'_local'.'/'.$module.'.php'; if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5061,7 +5061,7 @@ //if local directory not found, or particular string does not exist in local direcotry $langfile = $location.$parentlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5076,7 +5076,7 @@ foreach ($locations as $location) { $locallangfile = $location.$defaultlang.'_local/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5086,7 +5086,7 @@ $langfile = $location.$defaultlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5100,7 +5100,7 @@ foreach ($locations as $location) { $locallangfile = $location.$defaultlang.'_local/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5110,7 +5110,7 @@ $langfile = $location.$defaultlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5128,12 +5128,13 @@ * @param string $identifier ? * @param string $langfile ? * @param string $destination ? + * @param mixed $a Arbitrary parameter to get_string, used only for plurals * @return string|false ? * @staticvar array $strings Localized strings * @access private * @todo Finish documenting this function. */ -function get_string_from_file($identifier, $langfile, $destination) { +function get_string_from_file($identifier, $langfile, $destination, $a) { static $strings; // Keep the strings cached in memory. @@ -5149,6 +5150,16 @@ return false; } + // If the parameter is a low single-digit number, then search (in same + // file only) for a version specific to that number. This can be used to + // create grammatically-correct plurals. (Some languages have different + // grammar for 2 items and a few, possibly archaic, have 3.) Arbitrary + // integers could be supported, but this code is faster. + $stringa=(string)$a; + if (($stringa==='0' || $stringa==='1' || $stringa==='2' || $stringa==='3') && isset($string[$identifier.'_'.$stringa])) { + return $destination .'= sprintf("'. $string[$identifier.'_'.$stringa] .'");'; + } + return $destination .'= sprintf("'. $string[$identifier] .'");'; }