From 4ffa82df2afa703de5d58e5808950f920819e86c Mon Sep 17 00:00:00 2001 From: Martin Widmann Date: Tue, 27 Mar 2012 16:38:54 +0200 Subject: [PATCH] added rudimentary i18n support by adding date.format.js and adding an i18n object to VMM.master_config --- date.format.min.js | 1 + source/js/VMM.Util.js | 93 ++++++++----------------------------------- source/js/VMM.js | 28 +++++++++++++ source/js/timeline.js | 16 ++++---- 4 files changed, 54 insertions(+), 84 deletions(-) create mode 100644 date.format.min.js diff --git a/date.format.min.js b/date.format.min.js new file mode 100644 index 0000000..81ed458 --- /dev/null +++ b/date.format.min.js @@ -0,0 +1 @@ +var dateFormat=function(){var a=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,b=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,c=/[^-+\dA-Z]/g,d=function(a,b){a=String(a);b=b||2;while(a.length99?Math.round(q/10):q),t:n<12?"a":"p",tt:n<12?"am":"pm",T:n<12?"A":"P",TT:n<12?"AM":"PM",Z:g?"UTC":(String(e).match(b)||[""]).pop().replace(c,""),o:(r>0?"-":"+")+d(Math.floor(Math.abs(r)/60)*100+Math.abs(r)%60,4),S:["th","st","nd","rd"][j%10>3?0:(j%100-j%10!=10)*j%10]};return f.replace(a,function(a){return a in s?s[a]:a.slice(1,a.length-1)})}}();dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};dateFormat.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]};Date.prototype.format=function(a,b){return dateFormat(this,a,b)} \ No newline at end of file diff --git a/source/js/VMM.Util.js b/source/js/VMM.Util.js index 241f96d..ac04a7f 100644 --- a/source/js/VMM.Util.js +++ b/source/js/VMM.Util.js @@ -123,53 +123,47 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { // VMM.Util.date.day[0]; // VMM.Util.date.get12HRTime(time, seconds_true); date: { - // somestring = VMM.Util.date.month[2]; // Returns March - month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], - // somestring = VMM.Util.date.month_abbrev[1]; // Returns Feb. - month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."], - day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], - day_abbr: ["Sun.","Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."], - hour: [1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12], - hour_suffix: ["am"], - //VMM.Util.date.prettyDate(d, is_abbr) prettyDate: function(d, is_abbr, date_type) { var _date = ""; - if (type.of(d) == "date") { + + dateFormat.i18n = { + dayNames: VMM.master_config.i18n.date.day_abbr.concat( VMM.master_config.i18n.date.day ), + monthNames: VMM.master_config.i18n.date.month_abbr.concat( VMM.master_config.i18n.date.month ), + }; + if (d.getMonth() === 0 && d.getDate() == 1 && d.getHours() === 0 && d.getMinutes() === 0 ) { // trace("YEAR ONLY"); - _date = d.getFullYear(); + _date = dateFormat( d, VMM.master_config.i18n.dateformats.year ); } else { if (d.getDate() <= 1 && d.getHours() === 0 && d.getMinutes() === 0) { // trace("YEAR MONTH"); if (is_abbr) { - _date = VMM.Util.date.month_abbr[d.getMonth()]; - + _date = dateFormat( d, VMM.master_config.i18n.dateformats.month_short ); } else { - _date = VMM.Util.date.month[d.getMonth()] + " " + d.getFullYear() ; + _date = dateFormat( d, VMM.master_config.i18n.dateformats.month ); } } else if (d.getHours() === 0 && d.getMinutes() === 0) { // trace("YEAR MONTH DAY"); if (is_abbr) { - _date = VMM.Util.date.month_abbr[d.getMonth()] + " " + d.getDate(); + _date = dateFormat( d, VMM.master_config.i18n.dateformats.full_short ); } else { - _date = VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() ; + _date = dateFormat( d, VMM.master_config.i18n.dateformats.full ); } } else if (d.getMinutes() === 0) { // trace("YEAR MONTH DAY HOUR"); - if (is_abbr){ - //_date = VMM.Util.date.get12HRTime(d) + " " + (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear() ; - _date = VMM.Util.date.get12HRTime(d); + if (is_abbr) { + _date = dateFormat( d, VMM.master_config.i18n.dateformats.time_no_seconds_short ); } else { - _date = VMM.Util.date.get12HRTime(d) + "
" + VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " "; + _date = dateFormat( d, VMM.master_config.i18n.dateformats.time_no_seconds_small_date ); } } else { // trace("YEAR MONTH DAY HOUR MINUTE"); - if (is_abbr){ - _date = VMM.Util.date.day[d.getDay()] + ", " + VMM.Util.date.month_abbr[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " at " + VMM.Util.date.get12HRTime(d); + if (is_abbr) { + _date = dateFormat( d, VMM.master_config.i18n.dateformats.full_long ); } else { - _date = VMM.Util.date.get12HRTime(d) + "
" + VMM.Util.date.day[d.getDay()] + ", " + VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " "; + _date = dateFormat( d, VMM.master_config.i18n.dateformats.full_long ); } } @@ -184,59 +178,6 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { return _date; }, - - prettyMonth: function(m, is_year) { - var _month = ""; - if (type.of(t) == "date") { - - - } - return _month; - }, - - get12HRTime: function(t, is_seconds) { - var _time = ""; - - if (type.of(t) == "date") { - - _time = VMM.Util.date.theHour(t.getHours()) + ":" + VMM.Util.date.minuteZeroFill(t.getMinutes()); - - if (is_seconds) { - _time = _time + ":" + VMM.Util.date.minuteZeroFill(t.getSeconds()); - } - - _time = _time + VMM.Util.date.hourSuffix(t.getHours()); - - } - - return _time; - }, - - theHour: function(hr) { - if (hr > 0 && hr < 13) { - return (hr); - } - if (hr == "0") { - hr = 12; - return (hr); - } - if (hr === 0) { - return (12); - } - return (hr-12); - }, - minuteZeroFill: function(v) { - if (v > 9) { - return "" + v; - } - return "0" + v; - }, - hourSuffix: function(t) { - if (t < 12) { - return (" am"); - } - return (" pm"); - } }, // VMM.Util.doubledigit(number). diff --git a/source/js/VMM.js b/source/js/VMM.js index 4d60ea2..73c8f49 100644 --- a/source/js/VMM.js +++ b/source/js/VMM.js @@ -167,6 +167,34 @@ if (typeof VMM == 'undefined') { que: [] }, + i18n: { + date: { + month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."], + day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], + day_abbr: ["Sun.","Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."], + }, + dateformats: { + year: "yyyy", + month_short: "mmm", + month: "mmmm yyyy", + full_short: "mmm d", + full: "mmmm d',' yyyy", + time_no_seconds_short: "hh:MM TT", + time_no_seconds_small_date: "hh:MM TT'
'mmmm d',' yyyy''", + full_long: "dddd',' mmm d',' yyyy 'at' hh:MM TT", + full_long_small_date: "hh:MM TT'
'dddd',' mmm d',' yyyy''", + }, + messages: { + loading_timeline: "Loading Taimeline", + return_to_title: "Return to Title", + expand_timeline: "Expand Timeline", + contract_timeline: "Contract Timeline" + } + + } + + }).init(); /* Abstract out DOM element creation to make independent of library diff --git a/source/js/timeline.js b/source/js/timeline.js index 27fc0ae..f2ce7d3 100755 --- a/source/js/timeline.js +++ b/source/js/timeline.js @@ -58,7 +58,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { //VMM.attachElement($timeline, ""); $feedback = VMM.appendAndGetElement($timeline, "
", "feedback", ""); - $messege = VMM.appendAndGetElement($feedback, "
", "messege", "Loading Timeline"); + $messege = VMM.appendAndGetElement($feedback, "
", "messege", VMM.master_config.i18n.messages.loading_timeline); //VMM.appendElement($timeline, "
"); @@ -158,7 +158,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { function onComponentLoaded(e) { config.loaded.percentloaded = config.loaded.percentloaded + 25; - showMessege("Loading Timeline " + config.loaded.percentloaded); + showMessege(VMM.master_config.i18n.messages.loading_timeline + config.loaded.percentloaded); if (config.loaded.slider && config.loaded.timenav) { hideMessege(); } @@ -197,7 +197,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { //VMM.attachElement($timeline, ""); $feedback = VMM.appendAndGetElement($timeline, "
", "feedback", ""); - $messege = VMM.appendAndGetElement($feedback, "
", "messege", "Loading Timeline"); + $messege = VMM.appendAndGetElement($feedback, "
", "messege", VMM.master_config.i18n.messages.loading_timeline); }; @@ -1538,7 +1538,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { interval = interval_calc.second; //interval_major = interval_calc.minute; } else { - trace("NO FUCKING IDEA WHAT THE TYPE SHOULD BE"); + trace("NO ******* IDEA WHAT THE TYPE SHOULD BE"); interval.type = "unknown"; } @@ -1566,7 +1566,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { } else if (timespan.seconds > 1) { interval_major = interval_calc.minute; } else { - trace("NO FUCKING IDEA WHAT THE TYPE SHOULD BE"); + trace("NO ******* IDEA WHAT THE TYPE SHOULD BE"); interval_major.type = "unknown"; } @@ -1672,13 +1672,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { $zoomin = VMM.appendAndGetElement($toolbar, "
", "zoom-in", "
"); $zoomout = VMM.appendAndGetElement($toolbar, "
", "zoom-out", "
"); - VMM.Element.attribute($backhome, "title", "Return to Title"); + VMM.Element.attribute($backhome, "title", VMM.master_config.i18n.messages.return_to_title); VMM.Element.attribute($backhome, "rel", "tooltip"); - VMM.Element.attribute($zoomin, "title", "Expand Timeline"); + VMM.Element.attribute($zoomin, "title", VMM.master_config.i18n.messages.expand_timeline); VMM.Element.attribute($zoomin, "rel", "tooltip"); - VMM.Element.attribute($zoomout, "title", "Contract Timeline"); + VMM.Element.attribute($zoomout, "title", VMM.master_config.i18n.messages.contract_timeline); VMM.Element.attribute($zoomout, "rel", "tooltip"); VMM.bindEvent(".zoom-in", onZoomIn, "click");