Function loadLanguageFile() does now support extensions
authorRoland Häder <roland@mxchange.org>
Tue, 6 Oct 2009 20:26:19 +0000 (20:26 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 6 Oct 2009 20:26:19 +0000 (20:26 +0000)
inc/extensions.php
inc/language-functions.php

index c9865d7f835f205cabfbd4de8e9f5b91232eae5e..1b17f1101fac4658a573bf05fec6feb3d70bbd4d 100644 (file)
@@ -79,21 +79,8 @@ function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = '', $EXT_VER = '', $dry_run
                return false;
        } // END - if
 
                return false;
        } // END - if
 
-       // Construct FQFN for language file
-       $langInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
-
-       // Is this include there?
-       if ((isFileReadable($langInclude)) && (!isset($GLOBALS['ext_loaded']['lang'][$ext_name]))) {
-               // Then load it
-               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Language loaded.");
-               $GLOBALS['ext_loaded']['lang'][$ext_name] = true;
-               loadIncludeOnce($langInclude);
-       } elseif ((isDebugModeEnabled()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
-               // No language file is not so good...
-               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("WARNING: Extension %s has no language file or we cannot read from it. lang=%s",
-                       $ext_name, getLanguage()
-               ));
-       }
+       // Load extension's own language file
+       loadLanguageFile($ext_name);
 
        // Construct FQFN for functions file
        $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
 
        // Construct FQFN for functions file
        $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
index 5cde4b6ebe59fee6eaded2f5f8c65681dece0570..c2cde5f34ff215b79f018c289459040edd1a1094 100644 (file)
@@ -83,7 +83,7 @@ function getLanguage () {
                $ret = $GLOBALS['cache_array']['language'];
        } elseif (!empty($lang)) {
                // Check if main language file does exist
                $ret = $GLOBALS['cache_array']['language'];
        } elseif (!empty($lang)) {
                // Check if main language file does exist
-               if (isFileReadable(constant('PATH') . 'inc/language/'.$lang.'.php')) {
+               if (isFileReadable(constant('PATH') . 'inc/language/' . $lang . '.php')) {
                        // Okay found, so let's update cookies
                        setLanguage($lang);
                } // END - if
                        // Okay found, so let's update cookies
                        setLanguage($lang);
                } // END - if
@@ -112,7 +112,9 @@ function setLanguage ($lang) {
 }
 
 // Load the current language file or fixes it to 'de'
 }
 
 // Load the current language file or fixes it to 'de'
-function loadLanguageFile () {
+// If ext_name is empty, load general language support, else load extension's
+// language file.
+function loadLanguageFile ($ext_name = '') {
        // Try to get language from session
        $mx_lang = getSession('mx_lang');
 
        // Try to get language from session
        $mx_lang = getSession('mx_lang');
 
@@ -120,20 +122,34 @@ function loadLanguageFile () {
        if (is_null($mx_lang)) $mx_lang = getConfig('DEFAULT_LANG');
 
        // Generate filename
        if (is_null($mx_lang)) $mx_lang = getConfig('DEFAULT_LANG');
 
        // Generate filename
-       $INC = sprintf("inc/language/%s.php", SQL_ESCAPE($mx_lang));
+       if (empty($ext_name)) {
+               // Generic
+               $languageInclude = sprintf("inc/language/%s.php", SQL_ESCAPE($mx_lang));
+       } else {
+               // Extension's language file
+               $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
+       }
 
 
-       // Look for file
-       if (!isIncludeReadable($INC)) {
+       // Look for file if no extension name is provided
+       if ((empty($ext_name)) && (isIncludeReadable($languageInclude) === false)) {
                // Switch to default (DO NOT CHANGE!!!)
                setLanguage('de');
                // Switch to default (DO NOT CHANGE!!!)
                setLanguage('de');
-               $INC = 'inc/language/de.php';
+               $languageInclude = 'inc/language/de.php';
 
                // And set it temporarily
                setConfigEntry('DEFAULT_LANG', 'de');
        } // END - if
 
 
                // And set it temporarily
                setConfigEntry('DEFAULT_LANG', 'de');
        } // END - if
 
-       // Load language file
-       loadIncludeOnce($INC);
+       // Is the file there?
+       if (isIncludeReadable($languageInclude)) {
+               // Load language file
+               loadIncludeOnce($languageInclude);
+       } elseif ((isDebugModeEnabled()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
+               // No language file is not so good...
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("WARNING: Extension %s has no language file or we cannot read from it. lang=%s",
+                       $ext_name, getLanguage()
+               ));
+       }
 
        // Check for installation mode
        if ((isInstalling()) || (!isInstalled()) || (!isAdminRegistered())) {
 
        // Check for installation mode
        if ((isInstalling()) || (!isInstalled()) || (!isAdminRegistered())) {