]> git.mjollnir.org Git - moodle.git/commitdiff
Cleaned up get_string for language strings - slicker now
authormoodler <moodler>
Thu, 12 Jun 2003 03:27:24 +0000 (03:27 +0000)
committermoodler <moodler>
Thu, 12 Jun 2003 03:27:24 +0000 (03:27 +0000)
Added new feature: if a string "parentlanguage" exists then that
language will be tried before defaulting to English.

Useful for dialects or other languages that are similar.

For example, all the Spanish translations can default to "es"

lib/moodlelib.php

index a7cbfb5ff479d478a70e35e1073b1de831d37f5d..0b023ddac441ecac076ad3682db83985a27758f9 100644 (file)
@@ -996,35 +996,48 @@ function get_string($identifier, $module="", $a=NULL) {
     $langpath = "$CFG->dirroot/lang";
     $langfile = "$langpath/$lang/$module.php";
 
-    if (!file_exists($langfile)) {                // try English instead
-        $langfile = "$langpath/en/$module.php";
-        if (!file_exists($langfile)) {
-            return "ERROR: No lang file ($langpath/en/$module.php)!";
+    // Look for the string - if found then return it
+
+    if (file_exists($langfile)) {
+        if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
+            eval($result);
+            return $resultstring;
         }
     }
 
-    if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
-
-        eval($result);
-        return $resultstring;
+    // If the preferred language was English we can abort now
 
-    } else {
-        if ($lang == "en") {
-            return "[[$identifier]]";
+    if ($lang == "en") { 
+        return "[[$identifier]]";
+    }
 
-        } else {   // Try looking in the english file.
-            $langfile = "$langpath/en/$module.php";
-            if (!file_exists($langfile)) {
-                return "ERROR: No lang file ($langpath/en/$module.php)!";
-            }
-            if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
-                eval($result);
-                return $resultstring;
-            } else {
-                return "[[$identifier]]";
+    // Is a parent language defined?  If so, try it.
+            
+    if ($result = get_string_from_file("parentlanguage", "$langpath/$lang/moodle.php", "\$parentlang")) {
+        eval($result);
+        if (!empty($parentlang)) {
+            $langfile = "$langpath/$parentlang/$module.php";
+            if (file_exists($langfile)) {
+                if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
+                    eval($result);
+                    return $resultstring;
+                }
             }
         }
     }
+
+    // Our only remaining option is to try English
+
+    $langfile = "$langpath/en/$module.php";
+    if (!file_exists($langfile)) {
+        return "ERROR: No lang file ($langpath/en/$module.php)!";
+    }
+    if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
+        eval($result);
+        return $resultstring;
+    }
+
+    return "[[$identifier]]";  // Last resort
 }