CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with JavaScript encoding

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> PopCalendarXP Related
View previous topic :: View next topic  
Author Message
massimogentilini



Joined: 17 Jul 2006
Posts: 7

PostPosted: Wed Sep 27, 2006 8:06 am    Post subject: Problem with JavaScript encoding Reply with quote

We've developed a dynamic localize calendar aspx page to automatically localize calendar

Code:

private void Page_Load(object sender, System.EventArgs e)
      {
         // Localize calendar funcions
         // This dynamically generated javascript file contains all the information about the
         // culture for the calendar
         Response.Clear();
         Response.ContentType = "application/x-javascript";         
         // Response.Charset = "";
         //Response.Charset = "utf-8";
         //Response.ContentEncoding = System.Text.Encoding.UTF8;
         
         CultureInfo ci = LoggedUserManager.CurrentUser.Culture;
         StringBuilder sb = new StringBuilder();         
         
         
         // var giDatePos=0;   // date format sequence  0: D-M-Y ; 1: M-D-Y; 2: Y-M-D
         // Need to find the proper date format for the culture
         
         sb.Append(System.Environment.NewLine);
         DateTimeFormatInfo cf = ci.DateTimeFormat;
         string calDateFormat = " giDatePos=0;"; // Fallback in case of strange situations
         if(cf.ShortDatePattern.ToUpper().StartsWith("Y"))         
            calDateFormat = " giDatePos=2;";
         if(cf.ShortDatePattern.ToUpper().StartsWith("M"))         
            calDateFormat = " giDatePos=1;";
         sb.Append(calDateFormat);
         
         // Oversimplification: split according to date separator and use always the middle field
         // to check for month lenght and padding. Checked ONLY with English, Slovak, Czech, Svedish, Russian, Polish and Italian
         string[] dateTest = cf.ShortDatePattern.Split(ci.DateTimeFormat.DateSeparator.ToCharArray());
         if(dateTest[1].Trim().Length == 1) // Manage cultures with non 0 padding like slovak
            sb.Append("gbPadZero=false;");
         
         if(dateTest[1].StartsWith(" "))
            sb.Append(" gsSplit=\"" + ci.DateTimeFormat.DateSeparator + " \";");
         else
         //var gsSplit="/";   // separator of date string. If set it to empty string, then giMonthMode and gbPadZero will be fixed to 0 and true.         
            sb.Append(" gsSplit=\"" + ci.DateTimeFormat.DateSeparator + "\";");
            
         
         //var gMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
         sb.Append(System.Environment.NewLine)            
            .Append(" gMonths=[");
         for(int i=0; i<ci.DateTimeFormat.AbbreviatedMonthNames.Length-1; i++)
            sb.Append("\"" + ci.DateTimeFormat.AbbreviatedMonthNames[i].ToString() + "\",");
         sb.Remove(sb.Length-1,1); // remove last comma
         sb.Append("];");

         
         //var gWeekDay=["Su","Mo","Tu","We","Th","Fr","Sa"];   // weekday caption from Sunday to Saturday
         sb.Append(System.Environment.NewLine)            
            .Append(" gWeekDay=[");
         for(int i=0; i<ci.DateTimeFormat.AbbreviatedDayNames.Length; i++)
         if(ci.DateTimeFormat.AbbreviatedDayNames[i].ToString().Length > 2) // Manage situation for days with a single letter name (sunday in polish)
            sb.Append("\"" + ci.DateTimeFormat.AbbreviatedDayNames[i].ToString().Substring(0,2) + "\",");
         else
            sb.Append("\"" + ci.DateTimeFormat.AbbreviatedDayNames[i].ToString() + "\",");
         sb.Remove(sb.Length-1,1); // remove last comma
         sb.Append("];");

         // Generic functions, needed to properly align and define the calendar localization
         sb.Append(System.Environment.NewLine)
            .Append(" giFirstDOW=1;")
            .Append(System.Environment.NewLine)
            .Append(" giSat=(6-giFirstDOW)%7;")
            .Append(System.Environment.NewLine)
            .Append(" giSun=(7-giFirstDOW)%7;")
            .Append(System.Environment.NewLine)
            .Append(" gsOutOfRange=\"Invalid date!\";") // TODO, localize in multilanguage file as usual
            .Append(System.Environment.NewLine);

         sb.Append(System.Environment.NewLine);
         byte[] buf = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
         Response.AddHeader("Content-Length", buf.Length.ToString());
            Response.OutputStream.Write(buf, 0, buf.Length);
      
      }



and reference it using this

Code:
<iframe width=174 height=189 name="gToday:normal:agenda.js:gfPop:LocalizeCalendar.aspx" id="gToday:normal:agenda.js:gfPop:LocalizeCalendar.aspx" src="calendar/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;"></iframe>


Problem is that for the Czech culture it do not correctly show the day names, probably for some problem in the UTF encoding or character escaping.

We believe it's some problem related to IE6 and specific to this browser, because the same code works perfectly with IE7, Opera and Firefox.

Do you have any suggestion about how to set the encoding for JavaScript dynamically generated pages?

BTW: if someone uses this code and maybe improves it please let me know!

Ciao
Massimo
Back to top
View user's profile Send private message
massimogentilini



Joined: 17 Jul 2006
Posts: 7

PostPosted: Wed Sep 27, 2006 9:16 am    Post subject: Reply with quote

Sorry, already solved.

You need to pass utf-8 as the fifth parameter in the iframe part:

gToday:normal:agenda.js:gfPop:LocalizeCalendar.aspx:utf-8

Ciao
Massimo[/b]
Back to top
View user's profile Send private message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Wed Sep 27, 2006 12:36 pm    Post subject: Reply with quote

Yes, that's the correct solution that we were about to suggest. Good to know you found it sooner. :)
_________________
Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> PopCalendarXP Related All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group