当前位置:   article > 正文

Telerik Kendo UI 那点事【2】中文化(汉化)_kando ui 汉化

kando ui 汉化

CSDN上有一个引路蜂软件的博客,里面有kendo ui的一般用法。它那里讲过的我这里就不再继续重复。

由于框架设计的需要,后台使用spring,前台使用kendo ui构建页面。为了加快快发速度以及底层兼容性,义不容辞的,继续选择了hibernate作为数据库沟通的桥梁。spring方面的例子全网就更多了,主要采用spring注解方式的MVC配置,使用json数据映射器。

         经过初步的使用,发现kendo ui的设计极为强大,其MVVM的特性与spring的MVC特性结合,配合hibernate开发系统时,如列表呈现之类的,几乎都不需要写什么查询代码。

另外其中文化已经有人托管了文件在GitHub,直接配置后即可使用。对于日期的格式化的问题,经过本人多次尝试,也在汉化文件中通过简单设置,解决全局日期设置问题。

        下面就来详细介绍一下,如何达到上述效果:

一、中文化

本人的习惯,拿到不管是哪里的控件,第一是看demo炫不炫,代码量如何;第二就是看国际化支持,能不能支持中文语言字典文件之类的汉化,如果不能全局直接设置汉化,而是要逢用必改的话,那就一切免谈。kendo ui是过了我这两关。下面说下具体做法。

去下面这个网址,下载kendo.messages.zh-CN.js文件,就是kendo ui的中文国际化文件。

        https://github.com/telerik/kendo-ui-core/tree/master/src/messages

内容如下:

  1. /* FlatColorPicker messages */
  2. if (kendo.ui.FlatColorPicker) {
  3. kendo.ui.FlatColorPicker.prototype.options.messages =
  4. $.extend(true, kendo.ui.FlatColorPicker.prototype.options.messages,{
  5. "apply": "确定",
  6. "cancel": "取消"
  7. });
  8. }
  9. /* ColorPicker messages */
  10. if (kendo.ui.ColorPicker) {
  11. kendo.ui.ColorPicker.prototype.options.messages =
  12. $.extend(true, kendo.ui.ColorPicker.prototype.options.messages,{
  13. "apply": "确定",
  14. "cancel": "取消"
  15. });
  16. }
  17. /* ColumnMenu messages */
  18. if (kendo.ui.ColumnMenu) {
  19. kendo.ui.ColumnMenu.prototype.options.messages =
  20. $.extend(true, kendo.ui.ColumnMenu.prototype.options.messages,{
  21. "sortAscending": "升序",
  22. "sortDescending": "降序",
  23. "filter": "过滤",
  24. "columns": "列",
  25. "done": "完成",
  26. "settings": "列设置",
  27. "lock": "锁定",
  28. "unlock": "解除锁定"
  29. });
  30. }
  31. /* Editor messages */
  32. if (kendo.ui.Editor) {
  33. kendo.ui.Editor.prototype.options.messages =
  34. $.extend(true, kendo.ui.Editor.prototype.options.messages,{
  35. "bold": "粗体",
  36. "italic": "斜体",
  37. "underline": "下划线",
  38. "strikethrough": "删除线",
  39. "superscript": "上标",
  40. "subscript": "下标",
  41. "justifyCenter": "居中",
  42. "justifyLeft": "左对齐",
  43. "justifyRight": "右对齐",
  44. "justifyFull": "两端对齐",
  45. "insertUnorderedList": "插入无序列表",
  46. "insertOrderedList": "插入有序列表",
  47. "indent": "增加缩进",
  48. "outdent": "减少缩进",
  49. "createLink": "插入链接",
  50. "unlink": "移除链接",
  51. "insertImage": "插入图片",
  52. "insertFile": "插入文件",
  53. "insertHtml": "插入 HTML",
  54. "viewHtml": "查看 HTML",
  55. "fontName": "选择字体",
  56. "fontNameInherit": "(继承的字体)",
  57. "fontSize": "选择字号",
  58. "fontSizeInherit": "(继承的字号)",
  59. "formatBlock": "格式化块",
  60. "formatting": "格式化",
  61. "foreColor": "颜色",
  62. "backColor": "背景色",
  63. "style": "风格",
  64. "emptyFolder": "文件夹为空",
  65. "uploadFile": "上传",
  66. "orderBy": "排序条件:",
  67. "orderBySize": "大小",
  68. "orderByName": "名字",
  69. "invalidFileType": "选中的文件 \"{0}\" 非法,支持的文件类型为 {1}。",
  70. "deleteFile": '您确定要删除 \"{0}\"?',
  71. "overwriteFile": '当前文件夹已存在文件名为 \"{0}\" 的文件,您确定要覆盖么?',
  72. "directoryNotFound": "此文件夹未找到",
  73. "imageWebAddress": "图片地址",
  74. "imageAltText": "替代文本",
  75. "imageWidth": "宽度 (px)",
  76. "imageHeight": "高度 (px)",
  77. "fileWebAddress": "文件地址",
  78. "fileTitle": "标题",
  79. "linkWebAddress": "链接地址",
  80. "linkText": "链接文字",
  81. "linkToolTip": "链接提示",
  82. "linkOpenInNewWindow": "在新窗口中打开",
  83. "dialogUpdate": "上传",
  84. "dialogInsert": "插入",
  85. "dialogButtonSeparator": "或",
  86. "dialogCancel": "取消",
  87. "createTable": "创建表格",
  88. "addColumnLeft": "左侧添加列",
  89. "addColumnRight": "右侧添加列",
  90. "addRowAbove": "上方添加行",
  91. "addRowBelow": "下方添加行",
  92. "deleteRow": "删除行",
  93. "deleteColumn": "删除列"
  94. });
  95. }
  96. /* FileBrowser messages */
  97. if (kendo.ui.FileBrowser) {
  98. kendo.ui.FileBrowser.prototype.options.messages =
  99. $.extend(true, kendo.ui.FileBrowser.prototype.options.messages,{
  100. "uploadFile": "上传",
  101. "orderBy": "排序条件",
  102. "orderByName": "名称",
  103. "orderBySize": "大小",
  104. "directoryNotFound": "此文件夹未找到",
  105. "emptyFolder": "文件夹为空",
  106. "deleteFile": '您确定要删除 \"{0}\"?',
  107. "invalidFileType": "选中的文件 \"{0}\" 非法,支持的文件类型为 {1}。",
  108. "overwriteFile": "当前文件夹已存在文件名为 \"{0}\" 的文件,您确定要覆盖么?",
  109. "dropFilesHere": "拖拽要上传的文件到此处",
  110. "search": "搜索"
  111. });
  112. }
  113. /* FilterMenu messages */
  114. if (kendo.ui.FilterMenu) {
  115. kendo.ui.FilterMenu.prototype.options.messages =
  116. $.extend(true, kendo.ui.FilterMenu.prototype.options.messages,{
  117. "info": "显示符合以下条件的行",
  118. "isTrue": "为真",
  119. "isFalse": "为假",
  120. "filter": "过滤",
  121. "clear": "清除",
  122. "and": "并且",
  123. "or": "或",
  124. "selectValue": "-选择-",
  125. "operator": "运算符",
  126. "value": "值",
  127. "cancel": "取消"
  128. });
  129. }
  130. /* Filter menu operator messages */
  131. if (kendo.ui.FilterMenu) {
  132. kendo.ui.FilterMenu.prototype.options.operators =
  133. $.extend(true, kendo.ui.FilterMenu.prototype.options.operators,{
  134. "string": {
  135. "eq": "等于",
  136. "neq": "不等于",
  137. "startswith": "开头为",
  138. "contains": "包含",
  139. "doesnotcontain": "不包含",
  140. "endswith": "结尾为"
  141. },
  142. "number": {
  143. "eq": "等于",
  144. "neq": "不等于",
  145. "gte": "大于等于",
  146. "gt": "大于",
  147. "lte": "小于等于",
  148. "lt": "小于"
  149. },
  150. "date": {
  151. "eq": "等于",
  152. "neq": "不等于",
  153. "gte": "大于等于",
  154. "gt": "大于",
  155. "lte": "小于等于",
  156. "lt": "小于"
  157. },
  158. "enum": {
  159. "eq": "等于",
  160. "neq": "不等于"
  161. }
  162. });
  163. }
  164. /* Gantt messages */
  165. if (kendo.ui.Gantt) {
  166. kendo.ui.Gantt.prototype.options.messages =
  167. $.extend(true, kendo.ui.Gantt.prototype.options.messages,{
  168. "views": {
  169. "day": "日",
  170. "week": "周",
  171. "month": "月"
  172. },
  173. "actions": {
  174. "append": "添加任务",
  175. "addChild": "添加子任务",
  176. "insertBefore": "添加到前面",
  177. "insertAfter": "添加到后面"
  178. }
  179. });
  180. }
  181. /* Grid messages */
  182. if (kendo.ui.Grid) {
  183. kendo.ui.Grid.prototype.options.messages =
  184. $.extend(true, kendo.ui.Grid.prototype.options.messages,{
  185. "commands": {
  186. "cancel": "取消",
  187. "canceledit": "取消",
  188. "create": "新增",
  189. "destroy": "删除",
  190. "edit": "编辑",
  191. "save": "保存",
  192. "select": "选择",
  193. "update": "更新"
  194. },
  195. "editable": {
  196. "cancelDelete": "取消",
  197. "confirmation": "确定要删除吗?",
  198. "confirmDelete": "删除"
  199. }
  200. });
  201. }
  202. /* Groupable messages */
  203. if (kendo.ui.Groupable) {
  204. kendo.ui.Groupable.prototype.options.messages =
  205. $.extend(true, kendo.ui.Groupable.prototype.options.messages,{
  206. "empty": "托拽列标题到此处按列组合显示"
  207. });
  208. }
  209. /* NumericTextBox messages */
  210. if (kendo.ui.NumericTextBox) {
  211. kendo.ui.NumericTextBox.prototype.options =
  212. $.extend(true, kendo.ui.NumericTextBox.prototype.options,{
  213. "upArrowText": "增加",
  214. "downArrowText": "减少"
  215. });
  216. }
  217. /* Pager messages */
  218. if (kendo.ui.Pager) {
  219. kendo.ui.Pager.prototype.options.messages =
  220. $.extend(true, kendo.ui.Pager.prototype.options.messages,{
  221. "display": "显示条目 {0} - {1} 共 {2}",
  222. "empty": "没有可显示的记录。",
  223. "page": "页",
  224. "of": "共 {0}",
  225. "itemsPerPage": "每页",
  226. "first": "首页",
  227. "last": "末页",
  228. "next": "下一页",
  229. "previous": "上一页",
  230. "refresh": "刷新",
  231. "morePages": "更多..."
  232. });
  233. }
  234. /* PivotGrid messages */
  235. if (kendo.ui.PivotGrid) {
  236. kendo.ui.PivotGrid.prototype.options.messages =
  237. $.extend(true, kendo.ui.PivotGrid.prototype.options.messages,{
  238. "measureFields": "拖放数据字段于此",
  239. "columnFields": "拖放列字段于此",
  240. "rowFields": "拖放行字段于此"
  241. });
  242. }
  243. /* RecurrenceEditor messages */
  244. if (kendo.ui.RecurrenceEditor) {
  245. kendo.ui.RecurrenceEditor.prototype.options.messages =
  246. $.extend(true, kendo.ui.RecurrenceEditor.prototype.options.messages,{
  247. "frequencies": {
  248. "never": "从不",
  249. "hourly": "每小时",
  250. "daily": "每天",
  251. "weekly": "每周",
  252. "monthly": "每月",
  253. "yearly": "每年"
  254. },
  255. "hourly": {
  256. "repeatEvery": "重复周期: ",
  257. "interval": " 小时"
  258. },
  259. "daily": {
  260. "repeatEvery": "重复周期: ",
  261. "interval": " 天"
  262. },
  263. "weekly": {
  264. "interval": " 周",
  265. "repeatEvery": "重复周期: ",
  266. "repeatOn": "重复于:"
  267. },
  268. "monthly": {
  269. "repeatEvery": "重复周期: ",
  270. "repeatOn": "重复于:",
  271. "interval": " 月",
  272. "day": "日期"
  273. },
  274. "yearly": {
  275. "repeatEvery": "重复周期: ",
  276. "repeatOn": "重复于: ",
  277. "interval": " 年",
  278. "of": " 月份: "
  279. },
  280. "end": {
  281. "label": "截止时间:",
  282. "mobileLabel": "截止时间",
  283. "never": "从不",
  284. "after": "重复 ",
  285. "occurrence": " 次后",
  286. "on": "止于 "
  287. },
  288. "offsetPositions": {
  289. "first": "第一",
  290. "second": "第二",
  291. "third": "第三",
  292. "fourth": "第四",
  293. "last": "最后"
  294. },
  295. "weekdays": {
  296. "day": "天",
  297. "weekday": "工作日",
  298. "weekend": "周末"
  299. }
  300. });
  301. }
  302. /* Scheduler messages */
  303. if (kendo.ui.Scheduler) {
  304. kendo.ui.Scheduler.prototype.options.messages =
  305. $.extend(true, kendo.ui.Scheduler.prototype.options.messages,{
  306. "today": "今天",
  307. "save": "保存",
  308. "cancel": "取消",
  309. "destroy": "删除",
  310. "deleteWindowTitle": "删除事件",
  311. "ariaSlotLabel": "选择从 {0:t} 到 {1:t}",
  312. "ariaEventLabel": "{0} on {1:D} at {2:t}",
  313. "views": {
  314. "day": "日",
  315. "week": "周",
  316. "workWeek": "工作日",
  317. "agenda": "日程",
  318. "month": "月"
  319. },
  320. "recurrenceMessages": {
  321. "deleteWindowTitle": "删除周期条目",
  322. "deleteWindowOccurrence": "删除当前事件",
  323. "deleteWindowSeries": "删除序列",
  324. "editWindowTitle": "修改周期条目",
  325. "editWindowOccurrence": "修改当前事件",
  326. "editWindowSeries": "修改序列"
  327. },
  328. "editor": {
  329. "title": "标题",
  330. "start": "起始",
  331. "end": "终止",
  332. "allDayEvent": "全天事件",
  333. "description": "描述",
  334. "repeat": "重复",
  335. "timezone": " ",
  336. "startTimezone": "起始时区",
  337. "endTimezone": "终止时区",
  338. "separateTimezones": "使用独立的起始和终止时区",
  339. "timezoneEditorTitle": "时区",
  340. "timezoneEditorButton": "时区",
  341. "timezoneTitle": "选择时区",
  342. "noTimezone": "无",
  343. "editorTitle": "事件"
  344. }
  345. });
  346. }
  347. /* Slider messages */
  348. if (kendo.ui.Slider) {
  349. kendo.ui.Slider.prototype.options =
  350. $.extend(true, kendo.ui.Slider.prototype.options,{
  351. "increaseButtonTitle": "增加",
  352. "decreaseButtonTitle": "减少"
  353. });
  354. }
  355. /* TreeView messages */
  356. if (kendo.ui.TreeView) {
  357. kendo.ui.TreeView.prototype.options.messages =
  358. $.extend(true, kendo.ui.TreeView.prototype.options.messages,{
  359. "loading": "加载中...",
  360. "requestFailed": "加载失败",
  361. "retry": "重试"
  362. });
  363. }
  364. /* Upload messages */
  365. if (kendo.ui.Upload) {
  366. kendo.ui.Upload.prototype.options.localization =
  367. $.extend(true, kendo.ui.Upload.prototype.options.localization,{
  368. "select": "选择...",
  369. "cancel": "取消",
  370. "retry": "重试",
  371. "remove": "移除",
  372. "uploadSelectedFiles": "上传文件",
  373. "dropFilesHere": "拖拽要上传的文件到此处",
  374. "statusUploading": "上传中",
  375. "statusUploaded": "已上传",
  376. "statusWarning": "警告",
  377. "statusFailed": "失败",
  378. "headerStatusUploading": "上传...",
  379. "headerStatusUploaded": "完成"
  380. });
  381. }
  382. /* Validator messages */
  383. if (kendo.ui.Validator) {
  384. kendo.ui.Validator.prototype.options.messages =
  385. $.extend(true, kendo.ui.Validator.prototype.options.messages,{
  386. "required": "{0} 为必填项",
  387. "pattern": "{0} 非法",
  388. "min": "{0} 应该大于或等于 {1}",
  389. "max": "{0} 应该小于或等于 {1}",
  390. "step": "{0} 非法",
  391. "email": "{0} 不是合法的邮件地址",
  392. "url": "{0} 不是合法的URL",
  393. "date": "{0} 不是合法的日期"
  394. });
  395. }
  396. if(Date){
  397. Date.prototype.toISOString = function () {
  398. return kendo.toString(this, "yyyy-MM-dd HH:mm:ss");
  399. };
  400. }


注意最后的这个if(Date),是本人自己加的。主要是为了解决日期控件得到的时间date对象序列化的问题,date对象在向后台通信时,由于后台是spring的MVC框架,所以参数都通过kendo.stringify(XX)方法,或者JSON.stringify(XX)方法进行序列化,会默认调用Date对象的toISOString方法来格式化Date对象。通过在中文化文件中对Date对象的toISOString进行重写,从而达到兼容Spring后台MVC的目的,传递Date对象。格式与spring后台MVC json视图映射器的Date日期格式一直。这样才能保证Date类型对象,前后台传递没有问题。从gitHub下载的原始文件中不包含此内容。

有了国际化文件,到底怎么用呢?非常简单,直接在页面头部引入即可!

  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <%@ page contentType="text/html;charset=UTF-8"%>
  3. <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  4. <!DOCTYPE html >
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <link href="<c:url value='/resources/styles/kendo.common.min.css'/>"
  9. rel="stylesheet" />
  10. <link href="<c:url value='/resources/styles/kendo.rtl.min.css'/>"
  11. rel="stylesheet" />
  12. <link href="<c:url value='/resources/styles/kendo.uniform.min.css'/>"
  13. rel="stylesheet" />
  14. <script src="<c:url value='/resources/js/jquery.min.js' />"></script>
  15. <script src="<c:url value='/resources/js/kendo.web.min.js' />"></script>
  16. <script
  17. src="<c:url value='/resources/js/messages/kendo.messages.zh-CN.js' />"></script>
  18. <script
  19. src="<c:url value='/resources/js/cultures/kendo.culture.zh-CN.min.js' />"></script>
  20. <script>
  21. kendo.culture("zh-CN");
  22. </script>
  23. </head>
  24. ………………
  25. ………………
  26. </html>

注意<head>标签的最后3个标签行,kendo.messages.zh-CN.js负责提供所有控件的中文标签信息,使得控件中文化。kendo.culture.zh-CN.min.js里主要是一些日期、货币符号、时间格式、时区等等,不同国家不同的格式配置信息,可以根据需要修改,不过kendo已经提供了中文的文件,不需要我们再做什么操作。

汉化后的Gridview效果,如上述两图所示。效果非常好,并且是全局的,无忧无虑!敬请的使用吧!

再看看日历控件与Gridview的联合使用,并且配置进入Filter过滤器的效果:

 

     中文化就是这么简单!




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/47635
推荐阅读
相关标签
  

闽ICP备14008679号