From d0dc2b989c11d1d71334332917ca302f8a2e8b1c Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 10 Jan 2005 14:11:13 +0000 Subject: [PATCH] Moodle now supports language packs found under dataroot/lang (they 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 | 61 +++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index d4ad8e3aa1..31bd9e115b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 } /** -- 2.39.5