]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
caching language data
authorcash <cash.costello@gmail.com>
Thu, 26 Jan 2012 00:19:27 +0000 (19:19 -0500)
committercash <cash.costello@gmail.com>
Thu, 26 Jan 2012 00:19:27 +0000 (19:19 -0500)
engine/lib/cache.php
engine/lib/configuration.php
engine/lib/elgglib.php
engine/lib/languages.php

index 633c470eb066343f4e23c78dcf59842221bb55b4..c7e0ae31cc0971fa42b7dda7fc2f1e997f29db69 100644 (file)
@@ -455,6 +455,12 @@ function _elgg_cache_init() {
                        elgg_save_system_cache($type, serialize($CONFIG->$var_name));
                }
        }
+
+       if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) {
+               foreach ($CONFIG->translations as $lang => $map) {
+                       elgg_save_system_cache("$lang.php", serialize($map));
+               }
+       }
 }
 
 elgg_register_event_handler('ready', 'system', '_elgg_cache_init');
index 7f787331f13c1995c6e15a0b9b7344fee927f3cc..998cd194368532758cb7244e0a5546c0fd724559 100644 (file)
@@ -614,6 +614,8 @@ function _elgg_load_application_config() {
        $lastcached = datalist_get("simplecache_lastcached_$viewtype");
        $CONFIG->lastcache = $lastcached;
 
+       $CONFIG->i18n_loaded_from_cache = false;
+
        // this must be synced with the enum for the entities table
        $CONFIG->entity_types = array('group', 'object', 'site', 'user');
 }
index aba84bd4837b3c2fb2686c29838098ad25d1afeb..11bdc7285bdd70890eacb175f41cd65fc038a18b 100644 (file)
@@ -2062,7 +2062,8 @@ function elgg_walled_garden() {
  * 2. connects to database
  * 3. verifies the installation suceeded
  * 4. loads application configuration
- * 5. loads site configuration
+ * 5. loads i18n data
+ * 6. loads site configuration
  *
  * @access private
  */
@@ -2071,14 +2072,14 @@ function _elgg_engine_boot() {
        set_error_handler('_elgg_php_error_handler');
        set_exception_handler('_elgg_php_exception_handler');
 
-       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
-
        setup_db_connections();
 
        verify_installation();
 
        _elgg_load_application_config();
 
+       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
+
        _elgg_load_site_config();
 
        _elgg_load_cache();
index 80c789cedd51f659d8340f7c35d6086b655c288a..4dc094109d36529d630ac74e087fef71e956ab72 100644 (file)
@@ -155,7 +155,6 @@ 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(
@@ -165,6 +164,29 @@ function register_translations($path, $load_all = false) {
 
        $load_language_files = array_unique($load_language_files);
 
+       if ($CONFIG->system_cache_enabled && !$load_all) {
+               // load language files from cache
+               $data = array();
+               $loaded = true;
+               foreach ($load_language_files as $lang_file) {
+                       $lang = substr($lang_file, 0, strpos($lang_file, '.'));
+                       $data[$lang] = elgg_load_system_cache($lang_file);
+                       if (!$data[$lang]) {
+                               $loaded = false;
+                               break;
+                       }
+               }
+
+               if ($loaded) {
+                       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');
@@ -186,6 +208,8 @@ function register_translations($path, $load_all = false) {
                }
        }
 
+       elgg_log("Translations loaded from: $path");
+
        return $return;
 }