]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
rewrote the language caching - now not calling register_translations() if we can...
authorCash Costello <cash.costello@gmail.com>
Fri, 15 Jun 2012 01:05:11 +0000 (21:05 -0400)
committerCash Costello <cash.costello@gmail.com>
Fri, 15 Jun 2012 01:05:11 +0000 (21:05 -0400)
engine/lib/cache.php
engine/lib/elgglib.php
engine/lib/languages.php
engine/lib/plugins.php
engine/lib/sessions.php

index c117b9ec9cc18a800c53204f49ed87269dc09e0d..be1c43e14aee392d429bff8df50c65bdb8d736dd 100644 (file)
@@ -442,6 +442,7 @@ function _elgg_cache_init() {
        }
 
        if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) {
+               reload_all_translations();
                foreach ($CONFIG->translations as $lang => $map) {
                        elgg_save_system_cache("$lang.php", serialize($map));
                }
index db1464bd84c534bb783549b8f1098bd40c8e6560..8d4bbd64d1a15a8b6406fb942d9422798694f291 100644 (file)
@@ -2106,11 +2106,13 @@ function _elgg_engine_boot() {
 
        _elgg_load_application_config();
 
-       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
-
        _elgg_load_site_config();
 
+       _elgg_session_boot();
+
        _elgg_load_cache();
+
+       _elgg_load_translations();
 }
 
 /**
index 7a508d298408eb27173106740a7ff187ff9316d4..e55d5622a932a8e56056f55ec85c51938acf554f 100644 (file)
@@ -7,6 +7,57 @@
  * @subpackage Languages
  */
 
+/**
+ * Given a message key, returns an appropriately translated full-text string
+ *
+ * @param string $message_key The short message code
+ * @param array  $args        An array of arguments to pass through vsprintf().
+ * @param string $language    Optionally, the standard language code
+ *                            (defaults to site/user default, then English)
+ *
+ * @return string Either the translated string, the English string,
+ * or the original language string.
+ */
+function elgg_echo($message_key, $args = array(), $language = "") {
+       global $CONFIG;
+
+       static $CURRENT_LANGUAGE;
+
+       // old param order is deprecated
+       if (!is_array($args)) {
+               elgg_deprecated_notice(
+                       'As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.',
+                       1.8
+               );
+
+               $language = $args;
+               $args = array();
+       }
+
+       if (!$CURRENT_LANGUAGE) {
+               $CURRENT_LANGUAGE = get_language();
+       }
+       if (!$language) {
+               $language = $CURRENT_LANGUAGE;
+       }
+
+       if (isset($CONFIG->translations[$language][$message_key])) {
+               $string = $CONFIG->translations[$language][$message_key];
+       } else if (isset($CONFIG->translations["en"][$message_key])) {
+               $string = $CONFIG->translations["en"][$message_key];
+       } else {
+               $string = $message_key;
+       }
+
+       // only pass through if we have arguments to allow backward compatibility
+       // with manual sprintf() calls.
+       if ($args) {
+               $string = vsprintf($string, $args);
+       }
+
+       return $string;
+}
+
 /**
  * Add a translation.
  *
@@ -82,56 +133,34 @@ function get_language() {
        return false;
 }
 
-/**
- * Given a message shortcode, returns an appropriately translated full-text string
- *
- * @param string $message_key The short message code
- * @param array  $args        An array of arguments to pass through vsprintf().
- * @param string $language    Optionally, the standard language code
- *                            (defaults to site/user default, then English)
- *
- * @return string Either the translated string, the English string,
- * or the original language string.
- */
-function elgg_echo($message_key, $args = array(), $language = "") {
+function _elgg_load_translations() {
        global $CONFIG;
 
-       static $CURRENT_LANGUAGE;
-
-       // old param order is deprecated
-       if (!is_array($args)) {
-               elgg_deprecated_notice(
-                       'As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.',
-                       1.8
-               );
-
-               $language = $args;
-               $args = array();
-       }
+       if ($CONFIG->system_cache_enabled) {
+               $loaded = true;
+               $languages = array_unique(array('en', get_current_language()));
+               foreach ($languages as $language) {
+                       $data = elgg_load_system_cache("$language.php");
+                       if ($data) {
+                               add_translation($language, unserialize($data));
+                       } else {
+                               $loaded = false;
+                       }
+               }
 
-       if (!$CURRENT_LANGUAGE) {
-               $CURRENT_LANGUAGE = get_language();
-       }
-       if (!$language) {
-               $language = $CURRENT_LANGUAGE;
+               if ($loaded) {
+                       $CONFIG->i18n_loaded_from_cache = true;
+                       // this is here to force 
+                       $CONFIG->language_paths[dirname(dirname(dirname(__FILE__))) . "/languages/"] = true;
+                       return;
+               }
        }
 
-       if (isset($CONFIG->translations[$language][$message_key])) {
-               $string = $CONFIG->translations[$language][$message_key];
-       } else if (isset($CONFIG->translations["en"][$message_key])) {
-               $string = $CONFIG->translations["en"][$message_key];
-       } else {
-               $string = $message_key;
-       }
+       // load core translations from languages directory
+       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
+}
 
-       // only pass through if we have arguments to allow backward compatibility
-       // with manual sprintf() calls.
-       if ($args) {
-               $string = vsprintf($string, $args);
-       }
 
-       return $string;
-}
 
 /**
  * When given a full path, finds translation files and loads them
@@ -145,16 +174,9 @@ function elgg_echo($message_key, $args = array(), $language = "") {
 function register_translations($path, $load_all = false) {
        global $CONFIG;
 
-       static $load_from_cache;
-       static $cache_loaded_langs;
-       if (!isset($load_from_cache)) {
-               $load_from_cache = $CONFIG->system_cache_enabled;
-               $cache_loaded_langs = array();
-       }
-
        $path = sanitise_filepath($path);
 
-       // Make a note of this path just in case we need to register this language later
+       // Make a note of this path just incase we need to register this language later
        if (!isset($CONFIG->language_paths)) {
                $CONFIG->language_paths = array();
        }
@@ -162,6 +184,7 @@ function register_translations($path, $load_all = false) {
 
        // Get the current language based on site defaults and user preference
        $current_language = get_current_language();
+       elgg_log("Translations loaded from: $path");
 
        // only load these files unless $load_all is true.
        $load_language_files = array(
@@ -171,32 +194,6 @@ function register_translations($path, $load_all = false) {
 
        $load_language_files = array_unique($load_language_files);
 
-       if ($load_from_cache && !$load_all) {
-               // load language files from cache
-               $data = array();
-               foreach ($load_language_files as $lang_file) {
-                       $lang = substr($lang_file, 0, strpos($lang_file, '.'));
-                       if (!isset($cache_loaded_langs[$lang])) {
-                               $data[$lang] = elgg_load_system_cache($lang_file);
-                               if ($data[$lang]) {
-                                       $cache_loaded_langs[$lang] = true;
-                               } else {
-                                       // this language file not cached yet
-                                       $load_from_cache = false;
-                               }
-                       }
-               }
-
-               // are we still suppose to load from cache
-               if ($load_from_cache) {
-                       foreach ($data as $lang => $map) {
-                               add_translation($lang, unserialize($map));
-                       }
-                       $CONFIG->i18n_loaded_from_cache = true;
-                       return true;
-               }
-       }
-
        $handle = opendir($path);
        if (!$handle) {
                elgg_log("Could not open language path: $path", 'ERROR');
@@ -218,11 +215,6 @@ function register_translations($path, $load_all = false) {
                }
        }
 
-       elgg_log("Translations loaded from: $path");
-
-       // make sure caching code saves language data if system cache is on
-       $CONFIG->i18n_loaded_from_cache = false;
-
        return $return;
 }
 
index 39a76db5d9bcfaa3b129dfc217765a8ce8821b21..d5cd4fe769f30330a5e8ae5e2f429bb33b933da4 100644 (file)
@@ -311,6 +311,10 @@ function elgg_load_plugins() {
                $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS;
        }
 
+       if (elgg_get_config('i18n_loaded_from_cache')) {
+               $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES;
+       }
+
        $return = true;
        $plugins = elgg_get_plugins('active');
        if ($plugins) {
index 419d367076087bc2cc13cef2fe45691b5499c5ab..72ca0a1c220f8368a66ed8b24c690ce7587105d0 100644 (file)
@@ -376,14 +376,10 @@ function logout() {
  *
  * @uses $_SESSION
  *
- * @param string $event       Event name
- * @param string $object_type Object type
- * @param mixed  $object      Object
- *
  * @return bool
  * @access private
  */
-function _elgg_session_boot($event, $object_type, $object) {
+function _elgg_session_boot() {
        global $DB_PREFIX, $CONFIG;
 
        // Use database for sessions
@@ -464,9 +460,6 @@ function _elgg_session_boot($event, $object_type, $object) {
                return false;
        }
 
-       // Since we have loaded a new user, this user may have different language preferences
-       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
-
        return true;
 }
 
@@ -658,5 +651,3 @@ function _elgg_session_gc($maxlifetime) {
 
        return true;
 }
-
-elgg_register_event_handler('boot', 'system', '_elgg_session_boot', 2);