DataPicker does not display correct Chinese character

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
5/10/2008 10:56:26 AM
Gravatar
Total Posts 4

DataPicker does not display correct Chinese character

(1)DataPicker does not display correct Chinese character.

...Web\ClientScript\DatePicker\calendar-zh.js

I listed the codes in calendar-zh.js below: (I only added one line: Calendar._FD = 0; )

----------------------------------------------------------------

 

 

// ** I18N

// Calendar ZH language
// Author: muziq, <muziq@sina.com>
// Encoding: GB2312 or GBK
// Distributed under the same terms as the calendar itself.

// full day names
Calendar._DN = new Array
("星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日");

 

// Please note that the following array of short day names (and the same goes
// for short month names, _SMN) isn't absolutely necessary. We give it here
// for exemplification on how one can customize the short day names, but if
// they are simply the first N letters of the full name you can simply say:
//
// Calendar._SDN_len = N; // short day name length
// Calendar._SMN_len = N; // short month name length
//
// If N = 3 then this is not needed either since we assume a value of 3 if not
// present, to be compatible with translation files that were written before
// this feature.

// short day names
Calendar._SDN = new Array
("日",
"一",
"二",
"三",
"四",
"五",
"六",
"日");

// First day of the week. "0" means display Sunday first, "1" means display
// Monday first, etc.
Calendar._FD = 0;       // Added by me

// full month names
Calendar._MN = new Array
("一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月");

// short month names
Calendar._SMN = new Array
("一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月");

// tooltips
Calendar._TT = {};
Calendar._TT["INFO"] = "帮助";

Calendar._TT["ABOUT"] =
"DHTML Date/Time Selector\n" +
"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" + // don't translate this this ;-)
"For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
"\n\n" +
"选择日期:\n" +
"- 点击 \xab, \xbb 按钮选择年份\n" +
"- 点击 " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " 按钮选择月份\n" +
"- 长按以上按钮可从菜单中快速选择年份或月份";
Calendar._TT["ABOUT_TIME"] = "\n\n" +
"选择时间:\n" +
"- 点击小时或分钟可使改数值加一\n" +
"- 按住Shift键点击小时或分钟可使改数值减一\n" +
"- 点击拖动鼠标可进行快速选择";

Calendar._TT["PREV_YEAR"] = "上一年 (按住出菜单)";
Calendar._TT["PREV_MONTH"] = "上一月 (按住出菜单)";
Calendar._TT["GO_TODAY"] = "转到今日";
Calendar._TT["NEXT_MONTH"] = "下一月 (按住出菜单)";
Calendar._TT["NEXT_YEAR"] = "下一年 (按住出菜单)";
Calendar._TT["SEL_DATE"] = "选择日期";
Calendar._TT["DRAG_TO_MOVE"] = "拖动";
Calendar._TT["PART_TODAY"] = " (今日)";

// the following is to inform that "%s" is to be the first day of week
// %s will be replaced with the day name.
Calendar._TT["DAY_FIRST"] = "最左边显示%s";

// This may be locale-dependent. It specifies the week-end days, as an array
// of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1
// means Monday, etc.
Calendar._TT["WEEKEND"] = "0,6";

Calendar._TT["CLOSE"] = "关闭";
Calendar._TT["TODAY"] = "今日";
Calendar._TT["TIME_PART"] = "(Shift-)点击鼠标或拖动改变值";

// date formats
Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";
Calendar._TT["TT_DATE_FORMAT"] = "%A, %b %e日";

Calendar._TT["WK"] = "周";
Calendar._TT["TIME"] = "时间:";
----------------------------------------------------------------

(2) DatePicker was not displayed in correct position in IE 7.

 

5/10/2008 1:05:59 PM
Gravatar
Total Posts 18439

Re: DataPicker does not display correct Chinese character

Hi,

I will make the same change to fix the character.

I don't see any problem with the position of the datepicker in IE7.

Thanks for the fix!

Joe

5/10/2008 8:06:34 PM
Gravatar
Total Posts 4

Re: DataPicker does not display correct Chinese character

Hi, Joe

I fixed diplaying Chinese characters issue( DatePicker 显示简体中文日历 ).

The way was listed in my blog article (only work for Chinese Simplified , GB2312)

http://www.cnblogs.com/emanlee/archive/2008/05/11/1191888.html

Solution 1:(only work for Chinese user)

(1) alter calendar-cn_utf8.js(or cn_utf8.js,or calendar-zh.js),

add " Calendar._FD = 0; " into calendar-cn_utf8.js(or cn_utf8.js,or calendar-zh.js ), put this on the first line.

(2)  add charset=\"gb2312\" into \mojoPortal.Web.Controls\jsCalendarDatePicker.cs

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarmain","<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/calendar.js") + "\"></script>");

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarculture", "<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/" + this.LanguageFile) + "\" charset=\"gb2312\"></script>"); //Aimin

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"jscalendarsetup","<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/calendar-setup.js") + "\"></script>");

Solution 2:(better solution)

(1) alter calendar-cn_utf8.js(or cn_utf8.js,or calendar-zh.js),

add " Calendar._FD = 0; " into calendar-cn_utf8.js(or cn_utf8.js,or calendar-zh.js ), put this on the first line.

(2) Copy all codes in cn_utf8.js into calendar-zh.js  (overwrite the codes in calendar-zh.js)

 

Another issue:  Display Date Picker on IE 7.

I got the way:

 http://www.dynarch.com/forums/1993

And, I also added this into my aritcle

http://www.cnblogs.com/emanlee/archive/2008/05/11/1191888.html

 

Aimin

 

 

 

 

 

5/10/2008 8:21:35 PM
Gravatar
Total Posts 18439

Re: DataPicker does not display correct Chinese character

Hi Aimin,

First, good work in investigating this problem and coming up with a solution. However, I think a better solution exists, though its possible I am wrong, so don't be shy if you disagree :-).

I think that html and javascript is "supposed to be" encoded in utf-8 or unicode. If you replace the Chinese characters in the calendar-cn_utf8.js file with their unicode equivalent characters I think it will solve the problem without having to specify charset=\"gb2312\". Obviously figuring out the correct character set at runtime would be a maintenance problem to accomodate all languages, and if we can avoid that problem with a generic solution (unicode) that will be best.

I did a quick google and found this page which can convert the Chinese characters to Unicode:

http://www.pinyin.info/tools/converter/chars2uninumbers.html

Can you try that and then if it works, send me the updated .js file?

Best,

Joe

5/10/2008 9:59:41 PM
Gravatar
Total Posts 4

Re: DataPicker does not display correct Chinese character

Hi, Joe

Thank you for your advice.

In my opinion,  Convert 北京(Beijing) to &#21271;&#20140; and then put &#21271;&#20140; into calendar-zh.js ,

These unicode , such as &#21271;&#20140; , does not look friendly. (This way was described in http://www.pinyin.info/tools/converter/chars2uninumbers.html)

I tried a new solution to fix this issue. It works, look friendly , and change language dynamiclly at runtime.

Solution :

(1) alter  Web\ClientScript\DatePicker\lang\calendar-zh.js,

add " Calendar._FD = 0; " into  calendar-zh.js , put this on the first line or line 44 .

(2) alter  mojoPortal.Web.Controls\jsCalendarDatePicker.cs

//*************************************************

private void SetupScripts()
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarmain", "<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/calendar.js") + "\"></script>");

CalendarLanguage cl = (CalendarLanguage)Enum.Parse(typeof(CalendarLanguage), this.Language);
if (cl == CalendarLanguage.zh)
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarculture", "<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/" + this.LanguageFile) + "\" charset=\"gb2312\" ></script>");
}
else
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarculture", "<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/" + this.LanguageFile) + "\" ></script>");
}


this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarsetup", "<script type=\"text/javascript\" src=\""
+ ResolveUrl(this.ScriptDirectory + "/calendar-setup.js") + "\"></script>");

 

//*************************************************

 

I will send updated calendar-zh.js and jsCalendarDatePicker.cs to you via email .

 

Aimin

5/11/2008 7:00:26 AM
Gravatar
Total Posts 18439

Re: DataPicker does not display correct Chinese character

Hi,

I still think the conversion to unicode/utf-8 is the better soltion in this case. Yes its not friendly to read the file but this file is seldom read and even more seldom edited.

If we start putting if blocks for every language that has issues like this the code will be hard to maintain, we will have to keep adding more if statements.

Also since I do not have Chinese language on my machine, the characters all display as ?, (in the date picker) whereas in unicode I can see the characters correctly without installing Chinese language.

I agree that if there is a lot of text or the text is to be read/edited directly conversion to unicode is not a good solution, but for this small .js file that will hardly ever be read directly or edited, it is a better solution than starting down the path of adding if blocks or case statements for more languages.

If you look at other .js files for the date picker for other languages you will also see that many of them have unicode characters, ie calendar-tr.js. I think we should use the same solution for Chinese. These files have been there a long time and never need editing if they are correct.

So we see the same choices but we disagree on what is the right tradeoff. To me the unfriendliness of reading this file is not as important as keeping the C# code clean because the file is hardly ever read directly.

If you can convert the file to unicode it will be easier since you know Chinese and can be sure it is correct, but if you don't want to do it I can do it myself.

Best,

Joe

5/11/2008 8:22:01 AM
Gravatar
Total Posts 4

Re: DatePicker does not display correct Chinese character

Hi, Joe

I converted Chinese characters into Unicode characters according to your advice.

Here is the calendar-zh.js  , at the same time , I will send it to you via email.

 

//----------------------------------- begin


// ** I18N

// Calendar ZH language
// Author: muziq, <muziq@sina.com>
// Updated by: Aimin, <eman_lee@hotmail.com>
// Updated on: 05/11/2008
// Encoding: GB2312 or GBK
// Distributed under the same terms as the calendar itself.


// full day names
Calendar._DN = new Array
("&#26143;&#26399;&#26085;",
"&#26143;&#26399;&#19968;",
"&#26143;&#26399;&#20108;",
"&#26143;&#26399;&#19977;",
"&#26143;&#26399;&#22235;",
"&#26143;&#26399;&#20116;",
"&#26143;&#26399;&#20845;",
"&#26143;&#26399;&#26085;");

 

// Please note that the following array of short day names (and the same goes
// for short month names, _SMN) isn't absolutely necessary. We give it here
// for exemplification on how one can customize the short day names, but if
// they are simply the first N letters of the full name you can simply say:
//
// Calendar._SDN_len = N; // short day name length
// Calendar._SMN_len = N; // short month name length
//
// If N = 3 then this is not needed either since we assume a value of 3 if not
// present, to be compatible with translation files that were written before
// this feature.

// short day names
Calendar._SDN = new Array
("&#26085;",
"&#19968;",
"&#20108;",
"&#19977;",
"&#22235;",
"&#20116;",
"&#20845;",
"&#26085;");

// First day of the week. "0" means display Sunday first, "1" means display
// Monday first, etc.
Calendar._FD = 0;

// full month names
Calendar._MN = new Array
("&#19968;&#26376;",
"&#20108;&#26376;",
"&#19977;&#26376;",
"&#22235;&#26376;",
"&#20116;&#26376;",
"&#20845;&#26376;",
"&#19971;&#26376;",
"&#20843;&#26376;",
"&#20061;&#26376;",
"&#21313;&#26376;",
"&#21313;&#19968;&#26376;",
"&#21313;&#20108;&#26376;");

// short month names
Calendar._SMN = new Array
("&#19968;&#26376;",
"&#20108;&#26376;",
"&#19977;&#26376;",
"&#22235;&#26376;",
"&#20116;&#26376;",
"&#20845;&#26376;",
"&#19971;&#26376;",
"&#20843;&#26376;",
"&#20061;&#26376;",
"&#21313;&#26376;",
"&#21313;&#19968;&#26376;",
"&#21313;&#20108;&#26376;");

// tooltips
Calendar._TT = {};
Calendar._TT["INFO"] = "&#24110;&#21161;";

Calendar._TT["ABOUT"] =
"DHTML Date/Time Selector\n" +
"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" + // don't translate this this ;-)
"For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
"\n\n" +
"&#36873;&#25321;&#26085;&#26399;:\n" +
"- &#28857;&#20987; \xab, \xbb &#25353;&#38062;&#36873;&#25321;&#24180;&#20221;\n" +
"- &#28857;&#20987; " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " &#25353;&#38062;&#36873;&#25321;&#26376;&#20221;\n" +
"- &#38271;&#25353;&#20197;&#19978;&#25353;&#38062;&#21487;&#20174;&#33756;&#21333;&#20013;&#24555;&#36895;&#36873;&#25321;&#24180;&#20221;&#25110;&#26376;&#20221;";
Calendar._TT["ABOUT_TIME"] = "\n\n" +
"&#36873;&#25321;&#26102;&#38388;:\n" +
"- &#28857;&#20987;&#23567;&#26102;&#25110;&#20998;&#38047;&#21487;&#20351;&#25913;&#25968;&#20540;&#21152;&#19968;\n" +
"- &#25353;&#20303;Shift&#38190;&#28857;&#20987;&#23567;&#26102;&#25110;&#20998;&#38047;&#21487;&#20351;&#25913;&#25968;&#20540;&#20943;&#19968;\n" +
"- &#28857;&#20987;&#25302;&#21160;&#40736;&#26631;&#21487;&#36827;&#34892;&#24555;&#36895;&#36873;&#25321;";

Calendar._TT["PREV_YEAR"] = "&#19978;&#19968;&#24180; (&#25353;&#20303;&#20986;&#33756;&#21333;)";
Calendar._TT["PREV_MONTH"] = "&#19978;&#19968;&#26376; (&#25353;&#20303;&#20986;&#33756;&#21333;)";
Calendar._TT["GO_TODAY"] = "&#36716;&#21040;&#20170;&#26085;";
Calendar._TT["NEXT_MONTH"] = "&#19979;&#19968;&#26376; (&#25353;&#20303;&#20986;&#33756;&#21333;)";
Calendar._TT["NEXT_YEAR"] = "&#19979;&#19968;&#24180; (&#25353;&#20303;&#20986;&#33756;&#21333;)";
Calendar._TT["SEL_DATE"] = "&#36873;&#25321;&#26085;&#26399;";
Calendar._TT["DRAG_TO_MOVE"] = "&#25302;&#21160;";
Calendar._TT["PART_TODAY"] = " (&#20170;&#26085;)";

// the following is to inform that "%s" is to be the first day of week
// %s will be replaced with the day name.
Calendar._TT["DAY_FIRST"] = "&#26368;&#24038;&#36793;&#26174;&#31034;%s";

// This may be locale-dependent. It specifies the week-end days, as an array
// of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1
// means Monday, etc.
Calendar._TT["WEEKEND"] = "0,6";

Calendar._TT["CLOSE"] = "&#20851;&#38381;";
Calendar._TT["TODAY"] = "&#20170;&#26085;";
Calendar._TT["TIME_PART"] = "(Shift-)&#28857;&#20987;&#40736;&#26631;&#25110;&#25302;&#21160;&#25913;&#21464;&#20540;";

// date formats
Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";
Calendar._TT["TT_DATE_FORMAT"] = "%A, %b %e&#26085;";

Calendar._TT["WK"] = "&#21608;";
Calendar._TT["TIME"] = "&#26102;&#38388;:";

 

//----------------------------------------- end
 

Best,

Aimin

5/11/2008 8:36:56 AM
Gravatar
Total Posts 18439

Re: DataPicker does not display correct Chinese character

Excellent! Thank you very much!

I will update this by tonight in svn trunk and it will be in the new release coming tomorrow.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.