From: David ‘Bombe’ Roden Date: Sat, 20 Nov 2010 00:40:19 +0000 (+0100) Subject: Cache translations. X-Git-Tag: 0.3.1-RC1~54 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=1d1b1116e4e605f1e3ade0502cac73f8422c4501 Cache translations. --- diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index a346894..b8be6b3 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -99,6 +99,8 @@ function addCommentLink(postId, element) { }); } +var translations = {}; + /** * Retrieves the translation for the given key and calls the callback function. * The callback function takes a single parameter, the translated string. @@ -109,8 +111,13 @@ function addCommentLink(postId, element) { * The callback function */ function getTranslation(key, callback) { + if (key in translations) { + callback(translations[key]); + return; + } $.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) { if ((data != null) && data.success) { + translations[key] = data.value; callback(data.value); } }, function(xmlHttpRequest, textStatus, error) {