diff options
author | Yorhel <git@yorhel.nl> | 2010-11-25 17:22:58 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-11-25 17:38:16 +0100 |
commit | 625871cba8a2fe71c70b3d2946a5f37993d1f263 (patch) | |
tree | 1288db3b6ea43467251a6039a26e861326f0babe /data | |
parent | 7004c8352cda3c81e547aabc037fd9ec7f03172c (diff) |
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!
Diffstat (limited to 'data')
-rw-r--r-- | data/script.js | 10 |
1 files changed, 7 insertions, 3 deletions
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 /<perl regex>/ * any keys matching that regex will be included. * + * In the case of an mt('<key>') 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<arguments.length; i++) { var expr = '[_'+i+']'; while(val.indexOf(expr) >= 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<L10N_LANG.length; i++) { var ln = L10N_LANG[i]; var icon = tag('acronym', {'class':'icons lang '+ln}, ' '); - lst.appendChild(tag('li', {'class':'lang_selector'}, mt_curlang == ln + lst.appendChild(tag('li', {'class':'lang_selector'}, curlang == ln ? tag('i', icon, mt('_lang_'+ln)) : tag('a', {href:'/setlang?lang='+ln}, icon, L10N_STR['_lang_'+ln][ln]||mt('_lang_'+ln)) )); |