From b947c69a714a71e56325b7d90859d0c995ec9d8a Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 12 Jun 2003 03:27:24 +0000 Subject: [PATCH] Cleaned up get_string for language strings - slicker now 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 | 55 +++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a7cbfb5ff4..0b023ddac4 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 } -- 2.39.5