mirror of
				https://github.com/Mibew/mibew.git
				synced 2025-11-04 04:15:19 +03:00 
			
		
		
		
	Remove "$messages" global variable
This commit is contained in:
		
							parent
							
								
									36b817ac58
								
							
						
					
					
						commit
						ae92fe1514
					
				@ -150,46 +150,51 @@ function get_locale_links()
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Load localized messages id some service locale info.
 | 
					 * Load localized messages id some service locale info.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @global array $messages Localized messages array
 | 
					 * Messages are statically cached.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param string $locale Name of a locale whose messages should be loaded.
 | 
					 * @param string $locale Name of a locale whose messages should be loaded.
 | 
				
			||||||
 | 
					 * @return array Localized messages array
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function load_messages($locale)
 | 
					function load_messages($locale)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    global $messages;
 | 
					    static $messages = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Load core localization
 | 
					    if (!isset($messages[$locale])) {
 | 
				
			||||||
    $locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
 | 
					        // Load core localization
 | 
				
			||||||
    $locale_data = read_locale_file($locale_file);
 | 
					        $locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
 | 
				
			||||||
 | 
					        $locale_data = read_locale_file($locale_file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $messages[$locale] = $locale_data['messages'];
 | 
					        $messages[$locale] = $locale_data['messages'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Plugins are unavailable on system installation
 | 
					        // Plugins are unavailable on system installation
 | 
				
			||||||
    if (!installation_in_progress()) {
 | 
					        if (!installation_in_progress()) {
 | 
				
			||||||
        // Load active plugins localization
 | 
					            // Load active plugins localization
 | 
				
			||||||
        $plugins_list = array_keys(PluginManager::getAllPlugins());
 | 
					            $plugins_list = array_keys(PluginManager::getAllPlugins());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($plugins_list as $plugin_name) {
 | 
					            foreach ($plugins_list as $plugin_name) {
 | 
				
			||||||
            // Build plugin path
 | 
					                // Build plugin path
 | 
				
			||||||
            list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
 | 
					                list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
 | 
				
			||||||
            $plugin_name_parts = explode('_', $plugin_short_name);
 | 
					                $plugin_name_parts = explode('_', $plugin_short_name);
 | 
				
			||||||
            $locale_file = MIBEW_FS_ROOT
 | 
					                $locale_file = MIBEW_FS_ROOT
 | 
				
			||||||
                . "/plugins/" . ucfirst($vendor_name) . "/Mibew/Plugin/"
 | 
					                    . "/plugins/" . ucfirst($vendor_name) . "/Mibew/Plugin/"
 | 
				
			||||||
                . implode('', array_map('ucfirst', $plugin_name_parts))
 | 
					                    . implode('', array_map('ucfirst', $plugin_name_parts))
 | 
				
			||||||
                . "/locales/{$locale}/properties";
 | 
					                    . "/locales/{$locale}/properties";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get localized strings
 | 
					                // Get localized strings
 | 
				
			||||||
            if (is_readable($locale_file)) {
 | 
					                if (is_readable($locale_file)) {
 | 
				
			||||||
                $locale_data = read_locale_file($locale_file);
 | 
					                    $locale_data = read_locale_file($locale_file);
 | 
				
			||||||
                // array_merge used to provide an ability for plugins to override
 | 
					                    // array_merge used to provide an ability for plugins to override
 | 
				
			||||||
                // localized strings
 | 
					                    // localized strings
 | 
				
			||||||
                $messages[$locale] = array_merge(
 | 
					                    $messages[$locale] = array_merge(
 | 
				
			||||||
                    $messages[$locale],
 | 
					                        $messages[$locale],
 | 
				
			||||||
                    $locale_data['messages']
 | 
					                        $locale_data['messages']
 | 
				
			||||||
                );
 | 
					                    );
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return $messages[$locale];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -229,12 +234,7 @@ function read_locale_file($path)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function getstring_($text, $locale, $raw = false)
 | 
					function getstring_($text, $locale, $raw = false)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    global $messages;
 | 
					    $localized = load_messages($locale);
 | 
				
			||||||
    if (!isset($messages[$locale])) {
 | 
					 | 
				
			||||||
        load_messages($locale);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    $localized = $messages[$locale];
 | 
					 | 
				
			||||||
    if (isset($localized[$text])) {
 | 
					    if (isset($localized[$text])) {
 | 
				
			||||||
        return $raw
 | 
					        return $raw
 | 
				
			||||||
            ? $localized[$text]
 | 
					            ? $localized[$text]
 | 
				
			||||||
@ -373,5 +373,3 @@ function save_message($locale, $key, $value)
 | 
				
			|||||||
        fclose($fp);
 | 
					        fclose($fp);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
$messages = array();
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -29,14 +29,8 @@ $source = verify_param("source", "/^[\w-]{2,5}$/", DEFAULT_LOCALE);
 | 
				
			|||||||
$target = verify_param("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
 | 
					$target = verify_param("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
 | 
				
			||||||
$string_id = verify_param("key", "/^[_\.\w]+$/", "");
 | 
					$string_id = verify_param("key", "/^[_\.\w]+$/", "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (!isset($messages[$source])) {
 | 
					$lang1 = load_messages($source);
 | 
				
			||||||
    load_messages($source);
 | 
					$lang2 = load_messages($target);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
$lang1 = $messages[$source];
 | 
					 | 
				
			||||||
if (!isset($messages[$target])) {
 | 
					 | 
				
			||||||
    load_messages($target);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
$lang2 = $messages[$target];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page = array(
 | 
					$page = array(
 | 
				
			||||||
    'lang1' => $source,
 | 
					    'lang1' => $source,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user