]> git.mjollnir.org Git - moodle.git/commitdiff
Moodle now supports language packs found under dataroot/lang (they
authormoodler <moodler>
Mon, 10 Jan 2005 14:11:13 +0000 (14:11 +0000)
committermoodler <moodler>
Mon, 10 Jan 2005 14:11:13 +0000 (14:11 +0000)
take priority over all other locations).

Later we can add support to download language packs from within Moodle,
and edit/manage new packs more easily.

lib/moodlelib.php

index d4ad8e3aa10857b4558900f21729633a94933605..31bd9e115b2079653f5c7d2edf69cdcd1a78d9ad 100644 (file)
@@ -3078,23 +3078,17 @@ function get_string($identifier, $module='', $a=NULL) {
         $module = 'moodle';
     }
 
-    $langpath = $CFG->dirroot .'/lang';
-    $langfile = $langpath .'/'. $lang .'/'. $module .'.php';
+/// Define the two or three major locations of language strings for this module
 
-    // 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;
-        }
+    $locations = array( $CFG->dataroot.'/lang/',  $CFG->dirroot.'/lang/' );
+    if ($module != 'moodle') {
+        $locations[] =  $CFG->dirroot .'/mod/'.$module.'/lang/';
     }
 
-    // If it's a module, then look within the module pack itself mod/xxxx/lang/en/module.php
+/// First check all the normal locations for the string in the current language
 
-    if ($module != 'moodle') {
-        $modlangpath = $CFG->dirroot .'/mod/'. $module .'/lang';
-        $langfile = $modlangpath .'/'. $lang .'/'. $module .'.php';
+    foreach ($locations as $location) {
+        $langfile = $location.'/'.$lang.'/'.$module.'.php';
         if (file_exists($langfile)) {
             if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
                 eval($result);
@@ -3103,41 +3097,34 @@ function get_string($identifier, $module='', $a=NULL) {
         }
     }
 
-    // If the preferred language was English we can abort now
+/// If the preferred language was English we can abort now
     if ($lang == 'en') {
         return '[['. $identifier .']]';
     }
 
-    // Is a parent language defined?  If so, try it.
+/// Is a parent language defined?  If so, try to find this string in a parent language file
 
-    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;
+    foreach ($locations as $location) {
+        $langfile = $location.'/'.$lang.'/moodle.php';
+        if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang")) {
+            eval($result);
+            if (!empty($parentlang)) {   // found it!
+                $langfile = $location.'/'.$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
+/// 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;
-    }
+    foreach ($locations as $location) {
+        $langfile = $location.'/en/'.$module.'.php';
 
-    // If it's a module, then look within the module pack itself mod/xxxx/lang/en/module.php
-
-    if ($module != 'moodle') {
-        $langfile = $modlangpath .'/en/'. $module .'.php';
         if (file_exists($langfile)) {
             if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
                 eval($result);
@@ -3146,7 +3133,7 @@ function get_string($identifier, $module='', $a=NULL) {
         }
     }
 
-    return '[['. $identifier .']]';  // Last resort
+    return '[['.$identifier.']]';  // Last resort
 }
 
 /**