diff options
author | cash <cash.costello@gmail.com> | 2011-12-08 22:12:32 -0500 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-12-08 22:12:32 -0500 |
commit | 1ebbff44be8bccb87ec8cacee171d9b951ec50f4 (patch) | |
tree | fe6e50b397121415f0dbf841a81984447428c30d | |
parent | be930396dfd7c722d9c90d8987a49823710e6717 (diff) | |
download | elgg-1ebbff44be8bccb87ec8cacee171d9b951ec50f4.tar.gz elgg-1ebbff44be8bccb87ec8cacee171d9b951ec50f4.tar.bz2 |
Fixes #3181 caching language js on server side with proper headers
-rw-r--r-- | engine/lib/languages.php | 11 | ||||
-rw-r--r-- | js/lib/languages.js | 26 |
2 files changed, 27 insertions, 10 deletions
diff --git a/engine/lib/languages.php b/engine/lib/languages.php index 7607ea3bf..0400843af 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -301,4 +301,15 @@ function get_missing_language_keys($language) { return false; } +/** + * Initialize the language library + * @access private + */ +function elgg_languages_init() { + $lang = get_current_language(); + elgg_register_simplecache_view("cache/js/languages/$lang"); +} + +elgg_register_event_handler('init', 'system', 'elgg_languages_init'); + register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); diff --git a/js/lib/languages.js b/js/lib/languages.js index ae7ba63e2..bfa858364 100644 --- a/js/lib/languages.js +++ b/js/lib/languages.js @@ -26,16 +26,22 @@ elgg.add_translation = function(lang, translations) { elgg.reload_all_translations = function(language) { var lang = language || elgg.get_language(); - elgg.getJSON('ajax/view/js/languages', { - data: { - language: lang - }, - success: function(json) { - elgg.add_translation(lang, json); - elgg.config.languageReady = true; - elgg.initWhenReady(); - } - }); + var url, options; + if (elgg.config.simplecache_enabled) { + url = 'cache/js/default/languages/' + lang + '.' + elgg.config.lastcache + '.js'; + options = {}; + } else { + url = 'ajax/view/js/languages'; + options = {data: {language: lang}}; + } + + options['success'] = function(json) { + elgg.add_translation(lang, json); + elgg.config.languageReady = true; + elgg.initWhenReady(); + }; + + elgg.getJSON(url, options); }; /** |