Globalizr

I had an idea that was born from playing with the html5boilerplate as I rebuild an existing site. The current site is multi-homed with different TLD’s for english content and we also use a translation company that translates the site as is and hosts it at a site closer geographically to where the users would come from. All sites come from a single source but we’ve needed small variations depending on the TLD/Language. One instance was a product that was not available outside the United States, so on the .com site it needed to be there but on the .fr site it needed to be removed. The current site uses javascript to remove the navigation, but after playing with Modernizr I thought maybe we can do something similar.

I’m not a javascript guru but I managed to hack together something functional. We don’t go live until mid-may so i thought I’d put this out and see if anyone had any comments on the code.

window.Globalizr = (function(window,document,undefined){
   docElement = document.documentElement;
   classes = [];
   lang = '';
   var version = '0.1';
   ret = {};
   var d = document.domain.split('.');
   var l = d.length-1;
   var s = 0;
   classes.push(d[l]);
   var language = window.navigator.userLanguage || window.navigator.language;
   classes.push(language);
   if ('in,id,il,uk,nz,jp,kr,ck'.indexOf(d[l])>0) { s = -1; classes.push(d[l-1]); }
   if ((l+s) > 1) { classes.push(d[d.length-2+s]); }
   if ((l+s) > 1) { classes.push(d[d.length-3+s]); }
      else { classes.push('no-host'); }
   if (document.defaultCharset!=undefined) { classes.push(document.defaultCharset); }
      else { classes.push('no-defaultcharset'); }
   if (document.charset!=undefined) { classes.push(document.charset); }
      else { classes.push('no-charset'); }
   if (document.inputEncoding!=undefined) { classes.push(document.inputEncoding); }
      else { classes.push('no-inputencoding'); }
   docElement.className += classes.join(' ');
   return ret;
})(this,this.document);

Right now I have this code sitting right under the minified Modernizr code.

Posted in : javascript, tool