]> git.mjollnir.org Git - moodle.git/commitdiff
Soled bug 6089 plus some minor iteration savings...
authorstronk7 <stronk7>
Sat, 15 Jul 2006 08:39:50 +0000 (08:39 +0000)
committerstronk7 <stronk7>
Sat, 15 Jul 2006 08:39:50 +0000 (08:39 +0000)
(http://moodle.org/bugs/bug.php?op=show&bugid=6089)

Merged from MOODLE_16_STABLE

filter/multilang/filter.php

index ec71bd2e0d2069e7ca9184a3924637fd79f062a7..3360f02c2a25bcbe0990c00eeb972eb7c953c0b0 100644 (file)
@@ -105,6 +105,8 @@ function multilang_filter_impl($langblock) {
     $lang      = '';
     $minpref   = count($preflangs);
     $bestkey   = 0;
+    // Define the preference that will be enough if found
+    $stoppref = empty($CFG->unicodedb) ? 0 : 1;
     //Iterate
     foreach ($langlist[1] as $key => $lang) {
         //Normalize: Moodle's langs are always lowercase and they use the underscore
@@ -114,21 +116,13 @@ function multilang_filter_impl($langblock) {
         if ($foundkey !== false && $foundkey !== NULL && $foundkey < $minpref) {
             $minpref = $foundkey;
             $bestkey = $key;
-            if ($minpref == 0) {
-                continue;        //The best has been found. Leave iteration.
+            if ($minpref <= $stoppref) {
+                break;        //The best has been found. Leave iteration.
             }
         }
     }
 
-    // return result if we got some sort of match
-    if ($foundkey) {
-        $bestmatch = $langlist[2][$bestkey];
-    }
-    else {
-        $bestmatch = '';
-    }
-
-    return trim($bestmatch);
+    return trim($langlist[2][$bestkey]);
 }
 
 ?>