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. gcc选项-g与-rdynamic的异同_转

    转自:http://www.tuicool.com/articles/EvIzUn gcc 的 -g ,应该没有人不知道它是一个调试选项,因此在一般需要进行程序调试的场景下,我们都会加上该选项,并且根 ...

  2. VMware (威睿) 虚拟化产品简介

    VMware vSphere 是VMware(威睿)的一个虚拟化产品,VMware vSphere 是业界领先且最可靠的虚拟化平台.vSphere将应用程序和操作系统从底层硬件分离出来,从而简化了 I ...

  3. java对象占多少内存

    通常来说Hotspot jvm的对内存中的对象由以下几个部分组成 一个对象头,包含了一些整理工作所需信息 原始类型字段,不同类型大小各异(表1) 引用字段,占据4个字节(byte) 填充,在对象的末尾 ...

  4. 什么是JDK,JRE

    JDK 是Java开发工具包 (Java Development Kit ) 的缩写.它是一种用于构建在 Java 平台上发布的应用程序.applet 和组件的开发环境.其中包括了Java编译器.JV ...

  5. 二叉树的先序、中序以及后序遍历(递归 && 非递归)

    树节点定义: class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } 递归建立二 ...

  6. c语言的基本语法

    1. 二目运算符从右往左 优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右   () 圆括号 (表达式)/函数名(形参表)   . 成员选择(对象 ...

  7. SQL order 排序

    select * from emp;

  8. 转:Apache POI Tutorial

    Welcome to Apache POI Tutorial. Sometimes we need to read data from Microsoft Excel Files or we need ...

  9. C# 动态链接库的创建

    首先在C#工程下面安装第三方插件包 安装方法:Tools --> Library Package Manager --> Package Manager Console Install-P ...

  10. .NET: 配置文件

    VS里项目->添加新项->应用程序配置文件 <?xml version="1.0" encoding="utf-8" ?> <co ...