[web] Cache results from 'i18n' ajax controller (closes #4487856)
This is a simple transient cache which will be forgotten as soon as the
user leaves the current page.
--- a/web/data/cubicweb.ajax.js Wed Oct 15 17:29:29 2014 +0200
+++ b/web/data/cubicweb.ajax.js Wed Oct 15 18:23:54 2014 +0200
@@ -435,13 +435,21 @@
}
//============= higher level AJAX functions using remote calls ===============//
+
+var _i18ncache = {};
+
/**
* .. function:: _(message)
*
* emulation of gettext's _ shortcut
*/
function _(message) {
- return loadRemote(AJAX_BASE_URL, ajaxFuncArgs('i18n', null, [message]), 'GET', true)[0];
+ var form;
+ if (!(message in _i18ncache)) {
+ form = ajaxFuncArgs('i18n', null, [message]);
+ _i18ncache[message] = loadRemote(AJAX_BASE_URL, form, 'GET', true)[0];
+ }
+ return _i18ncache[message];
}
/**