From 625871cba8a2fe71c70b3d2946a5f37993d1f263 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 25 Nov 2010 17:22:58 +0100 Subject: JS: Split script.js into a separate file for each language This greatly reduces the size of the Javascript file. The compressed size has been reduced with about 9kB, and is now a total of 14kB for en.js. A nice property of this is that more translations can be added without increasing the JS size. While I was at it, I made jsgen.pl also replace mt() function calls in cases where an exact TL string was requested without any additional arguments and/or formatting codes. This helped reduce the compressed size by about 1kB. My aim is to keep *all* the JS code of VNDB smaller than the jQuery core library, as a general "fuck you" towards users of large and bloated JS libraries. We must keep the VNDB page loading times lower than that of other sites, after all! --- data/script.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'data') diff --git a/data/script.js b/data/script.js index 581b6494..696de64d 100644 --- a/data/script.js +++ b/data/script.js @@ -31,6 +31,10 @@ * l10n // * any keys matching that regex will be included. * + * In the case of an mt('') without any extra arguments, the entire + * function call may be replaced by the TL string. In such a case mt() + * behaves similar to a preprocessor macro in C. + * * The "_lang_*" keys for all languages for which we have a translation are * already included automatically. */ @@ -181,10 +185,9 @@ function shorten(v, l) { * - Only supports [_n], ~[, ~] * - When it finds [quant,_n,..], it will only return the first argument (and doesn't support ~ in an argument) * assumes that a TL structure called 'L10N_STR' is defined in the header of this file */ -var mt_curlang = byName(byId('lang_select'), 'acronym')[0].className.substr(11, 2); function mt() { var key = arguments[0]; - var val = L10N_STR[key] ? L10N_STR[key][mt_curlang] || L10N_STR[key].en : key; + var val = L10N_STR[key] ? L10N_STR[key] : key; for(var i=1; i= 0) @@ -2229,12 +2232,13 @@ if(byId('advselect') && byId('ti')) { // Language selector if(byId('lang_select')) { var d = byId('lang_select'); + var curlang = byName(d, 'acronym')[0].className.substr(11, 2); ddInit(d, 'bottom', function(lnk) { var lst = tag('ul', null); for(var i=0; i