1 引用本地化语言包

在 js/i18n 文件夹中,提供了大量预定义的语言包。它包括为所有字符串定义的,包括消息,标题,分页信息,搜索/添加/删除 的对话框 文本等。

在jQuery库文件后,在jqGrid 脚本文件前 引用语言包。

<head id="Head1" runat="server"> <!-- The jQuery UI theme that will be used by the grid -->> <link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.7.1.custom.css"/> <!-- The jQuery UI theme extension jqGrid needs -->> <link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css"/> <!-- jQuery runtime minified -->> <script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script> <!-- The localization file we need, English in this case -->> <script src="/js/i18n/grid.locale-en.js" type="text/javascript"></script> <!-- The jqGrid client-side javascript -->> <script src="/js/jquery.jqGrid.min.js" type="text/javascript"></script> </head>

2 修改创建语言包

$.jgrid = { defaults : { recordtext: "View {0} - {1} of {2}", emptyrecords: "No records to view", loadtext: "Loading...", pgtext : "Page {0} of {1}" }, search : { caption: "Search...", Find: "Find", Reset: "Reset", odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with', 'does not begin with','is in','is not in','ends with', 'does not end with','contains','does not contain'], groupOps: [ { op: "AND", text: "all" }, { op: "OR", text: "any" } ], matchText: " match", rulesText: " rules" }, ...

formatter : { integer : {thousandsSeparator: " ", defaultValue: '0'}, number : {decimalSeparator:".", thousandsSeparator: " ", decimalPlaces: 2, defaultValue: '0.00'}, currency : {decimalSeparator:".", thousandsSeparator: " ", decimalPlaces: 2, prefix: "", suffix:"", defaultValue: '0.00'}, date : { dayNames: [ "Sun", "Mon", "Tue", "Wed", "Thr", "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" ], ...

通过修改 这些文本,可以达到自定义的目的。

3 以代码的方式,重写语言默认的文本

可以在 Model 和 Controller 中以代码的方式,改变 edit dialog 的文本。

改变之前,默认为:

edit : { editCaption: "Edit Record", bSubmit: "Submit", bCancel: "Cancel" }

在 Controller 中改变

JQGridModel.EditDialogSettings.Caption = "My New Caption";
JQGridModel.EditDialogSettings.SubmitText = "My Submit Text";
JQGridModel.EditDialogSettings.CancelText = "My Cancel Text";

4 以代码的方式,改变语言包

在这种情况下,与其直接将文件添加懂啊header,不如使用 viewData 替代。

<head id="Head1" runat="server"> ... <script type="text/javascript" src="http://www.trirand.net/aspnetmvc/Scripts/jquery-1.3.2.min.js"></script> <script type="text/javascript" src='<%= ViewData["localeScript"] %>'></script> <script type="text/javascript" src="http://www.trirand.net/aspnetmvc/Scripts/jqgrid/jquery.jqGrid.min.js"></script> ... </head>

这会默认使用 英语。我们可以在服务端代码中修改。如Controller:

// locale can be passed as a GET parameter from a dropdownlist for example public ActionResult FunctionalityLocalization(string locale) { string jsLocale = locale ??"grid.locale-en.js"; ViewData["localesList"] = GetLocales(jsLocale); ViewData["localeScript"] ="http://www.trirand.net/aspnetmvc/Scripts/jqgrid/i18n/"+ jsLocale; // Pass the custmomized grid model to the View return View(GetGridModel()); } public SelectList GetLocales(string selectedValue) { List<SelectListItem> countries =new List<SelectListItem>(); countries.Add(new SelectListItem { Text ="English", Value ="grid.locale-en.js" }); countries.Add(new SelectListItem { Text ="German", Value ="grid.locale-de.js" }); countries.Add(new SelectListItem { Text ="French", Value ="grid.locale-fr.js" }); returnnew SelectList(countries, "Value", "Text", selectedValue); }

【jqGrid for ASP.NET MVC Documentation】.学习笔记.3.本地化语言包的更多相关文章

  1. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.4.性能

    1 HTML / ViewState 大小 1.1 HTML 大小 jqGrid for ASP.NET MVC 使用最佳的客户端渲染,意味着 HTML gird 的 尺寸是最小的.事实上,只有 gr ...

  2. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.2.jqGrid Model-View-Controller 分离

    1 基本 分离代码 和 描述 ,在ASP.NET MVC 应用程序中是非常重要的.因此,jqGrid 的 mvc 模式使用一个共同的网格安装设置,包括 Model ,Controller 和 View ...

  3. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.1.介绍

    1 介绍 jqGrid for ASP.NET MVC 是一个服务端组件. 专为MVC    分隔 model ,view , controller 的原则,完全观察者模式 非常快的速度    仅仅很 ...

  4. ASP.NET MVC Routing学习笔记(一)

    Routing在ASP.NET MVC中是非常核心的技术,属于ASP.NET MVC几大核心技术之一,在使用Routing之前,得先引入System.Web.Routing,但其实不用这么麻烦,因为在 ...

  5. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.7.搜索过滤数据

    1 基础 搜索和过滤功能,是使用确定的条件,查找匹配行数据.jqGrid提供几种搜索模式: Search Dialog 单搜索选项 Search Dialog 多搜索选项 ToolBar Search ...

  6. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.6.分层

    1 两级分层 每个父 grid 的行,都能有子 grid .这被叫做 层次,它用来显示相关的 表,主信息 –> 明细信息等. } 一旦你为 父子 grid 都定义了 Models ,下一步就是设 ...

  7. 精通 ASP.NET MVC 4 学习笔记(一)

    这里记录着从 P132 到 P192 的内容.水分很足,大部分是书上的代码,我只加了一些基于我自己的理解的能帮助初学者看懂的注释,并且把书中的部分内容做了一些的拓展. 建立数据层 设置 DI 容器 / ...

  8. ASP.NET MVC过滤器学习笔记

    1.过滤器的两个特征 1.他是一种特性,可以引用到控制器类和Action方法上.比如下图 这里控制器类和action方法都引用了过滤器,这个过滤器是用来做授权的 2.特征继承自FilterAttrib ...

  9. sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)

    sql server 关于表中只增标识问题   由于我们系统时间用的过长,数据量大,设计是采用自增ID 我们插入数据的时候把ID也写进去,我们可以采用 关闭和开启自增标识 没有关闭的时候 ,提示一下错 ...

随机推荐

  1. Android 开发之如何保证Service不被杀掉(broadcast+system/app)

    序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台运行,不管用户作出什么操作,都要保证service不被kill,这可真是一个难题.参考了现今各种定制版的系统和安全厂商牛虻 ...

  2. JDK和Tomcat的安装与配置

    1       JDK的安装 2       JDK的配置 3       JDK安装成功的验证 4       Tomcat的安装 (1)     解压” apache-tomcat-6.0.35. ...

  3. WW多线程和锁

    问题: WorldWind中是双线程的,一直忽略了多线程中数据共享,修改数据会产生问题.可是在WW中并没有看到锁的东西. 还有就是动态释放内存的问题.因为采用D3D的C#封装库不可避免涉及COM对象的 ...

  4. lua序列化(支持循环引用)

    lua序列化 支持key类型为string, number 支持value类型为string, number, table, boolean 支持循环引用 支持加密序列化 支持loadstring反序 ...

  5. Better PostgreSQL datacenter schema

  6. Python学习总结15:时间模块datetime & time & calendar (二)

    二 .datetime模块  1. datetime中常量 1)datetime.MINYEAR,表示datetime所能表示的最小年份,MINYEAR = 1. 2)datetime.MAXYEAR ...

  7. Java基础(42):Java中主类中定义方法加static和不加static的区别(前者可以省略类名直接在主方法调用,后者必须先实例化后用实例调用)

    package lsg.ap.april4th2; /* 知识点:1.Getter and Setter 的应用 2.局部变量与成员变量(也可叫做全局变量) 3.Static关键字的用法 a.成员变量 ...

  8. DataBase: MySQL在.NET中的应用

    首先需要下载MySQL: 1. 官方下载 dev.mysql.com/downloads/mysql/ 2. 解压到你所想要安装的位置,在文件夹里创建my.ini文件 [mysql] # 设置mysq ...

  9. Android studio删除工程项目,androidstudio

    本新手最近学Android都是用的eclipse.其实个人觉得eclipse不错,可能接触Android不久,倒也不觉得它慢还是怎样.对于Google的Android studio也是早有耳闻,前两天 ...

  10. c++中的传参问题

    从概念上讲.指针从本质上讲就是存放变量地址的一个变量,在逻辑上是独立的,它可以被改变,包括其所指向的地址的改变和其指向的地址中所存放的数据的改变. 而引用是一个别名,它在逻辑上不是独立的,它的存在具有 ...