解决AjaxFileUpload中文化/国际化的问题。
由微软官方提供的AjaxControlToolKit,在ASP.NET开发过程中,确实能够给开发者带来很多的便利,节约开发者的重复劳动。这套控件也是比较成熟的,在性能方面也不会太差,至少能够满足一般开发的需求。
目前,在工作中,需要使用到微软的AjaxFileUpload多文件异步上传控件,这个控件有以下几个优势:1,可以实现多个文件上传。2,文件上传具备有进度显示。3,可以限制图片上传类型和上传数量。4,使用方便,控件式开发。
但是,唯一不足,令人想吐槽的就是这个控件的国际化支持,实在太差了。他不能够像其他控件,指定UICulture='auto'就能自动匹配语言,在网上搜索中文网页的结果,也总是那么几条解决方法,而且看得一头雾水(可能版本不对,我使用版本的是 June 2013 Release),哎,尼玛,网上说得都是啥。
没办法,凭借多年的经验,中国人解决不了的问题,外国人早已经解决了,我还是准备求教GOOGLE大神,另外还有堆栈流(StackOverFlow,呵呵~)。好吧,经过不到几分钟地探索,尼玛,还真有答案。于是,我在以下地址,找到了解决方案:
http://forums.asp.net/t/1818037.aspx/1
贴出代码如下:
<script type="text/javascript"> //需要 Jquery支持 $(document).ready(function () { AjaxFileUpload_change_text(); }); function AjaxFileUpload_change_text() { //对应更改你想要显示的文字吧。 Sys.Extended.UI.Resources.AjaxFileUpload_SelectFile = "Select File"; Sys.Extended.UI.Resources.AjaxFileUpload_DropFiles = "Drop files here"; Sys.Extended.UI.Resources.AjaxFileUpload_Pending = "pending"; Sys.Extended.UI.Resources.AjaxFileUpload_Remove = "Remove"; Sys.Extended.UI.Resources.AjaxFileUpload_Upload = "Upload"; Sys.Extended.UI.Resources.AjaxFileUpload_Uploaded = "Uploaded"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage = "uploaded {0} %"; Sys.Extended.UI.Resources.AjaxFileUpload_Uploading = "Uploading"; Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue = "{0} file(s) in queue."; Sys.Extended.UI.Resources.AjaxFileUpload_AllFilesUploaded = "All Files Uploaded."; Sys.Extended.UI.Resources.AjaxFileUpload_FileList = "List of Uploaded files:"; Sys.Extended.UI.Resources.AjaxFileUpload_SelectFileToUpload = "Please select file(s) to upload."; Sys.Extended.UI.Resources.AjaxFileUpload_Cancelling = "Cancelling..."; Sys.Extended.UI.Resources.AjaxFileUpload_UploadError = "An Error occured during file upload."; Sys.Extended.UI.Resources.AjaxFileUpload_CancellingUpload = "Cancelling upload..."; Sys.Extended.UI.Resources.AjaxFileUpload_UploadingInputFile = "Uploading file: {0}."; Sys.Extended.UI.Resources.AjaxFileUpload_Cancel = "Cancel"; Sys.Extended.UI.Resources.AjaxFileUpload_Canceled = "cancelled"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled = "File upload cancelled"; Sys.Extended.UI.Resources.AjaxFileUpload_DefaultError = "File upload error"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadingHtml5File = "Uploading file: {0} of size {1} bytes."; Sys.Extended.UI.Resources.AjaxFileUpload_error = "error"; } </script>
需要严重提醒,这个解决方案有一个弊端,就是对浏览器兼容性不够好,目前只测试了FireFox首次加载无法替换中文问题,IE系列浏览器支持良好。但是不必担心,存在这种问题的开发者的客户一般都是中国人,“IE6,你懂的“。
最后,通过这件事情,充分地证明了学好英语的好处,也充分地证明,百度是极其不适合程序员的一个网站,就像那一句广告语吧:珍爱生命,远离百度。
PS:
(这篇文章也可以解决:ajaxFileUpload如何显示中文,AjaxFileUpload如何支持中文等等之类的换个说法的问题。)