All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
包含实时功能的ASP.NET系统结构_.net资料_编程技术
一步步教你配置SQL SERVER合并复制(四)设置Distributor的安全_[SQL Server教程]
XMLHTTP对象应用开发的初体验_[XML教程]
上传图片生成略缩图“最佳解决”_[Asp.Net教程]
动态网页制作技巧PHP:详细彻底学习Smarty_[PHP教程]
SQL注入技术和跨站脚本攻击的检测_[SQL,Server教程]
解决phpmyadmin 乱码,支持gb2312和utf-8_[PHP教程]
ASP.NET底层架构探索之HttpHandlers_.net资料_编程技术
VS2005中的WebSite和WebApplication有何区别_.net资料_编程技术
通过继承ConfigurationSection,在web.config中增加自定义配置_[Asp.Net教程]
Reading number is top 10 pictures
Go to the national museum1
Small s breast enhancement demonstration
Beauty shocked Japan Tokyo motor show model
mythology hero1
随便发几张图
人美胸美腿更美1
小学生作文又现神作,你不得不佩服
Kim jong il's mistress, national beauty JinYuJi actor3
More attractive than sora aoi4
美女
Download software ranking
仙剑奇侠传98硬盘WINXP版
matrix3
C++编程教程第三版
c#程序设计案例教程
jBuilder2006
Boxer Classic video3
WebService在.NET中的实战应用教学视频 → 第2集
Wild things 2
Unix video tutorial5
软件工程思想
归海一刀 published in(发表于) 2014/1/30 1:12:09 Edit(编辑)
温故知新ASP.NET,2.0(C#)(5),-,Localization(本地化,多语言)_[Asp.Net教程]

温故知新ASP.NET,2.0(C#)(5),-,Localization(本地化,多语言)_[Asp.Net教程]

温故知新ASP.NET 2.0(C#)(5) - Localization(本地化,多语言)_[Asp.Net教程]

介绍
声明性资源表达式可使您的应用程序使用多种语言,而不必手动编写代码来检索资源并在页中进行替换。您只需使用 ASP.NET 2.0 中新提供的表达式语法即可对资源替换进行定义。ASP.NET 2.0 支持标准的 resx 文件格式自动进行运行时资源检索。



关键
1、Culture - 决定各种数据类型是如何组织,如数字与日期;UICulture - 决定了采用哪一种本地化资源,也就是使用哪种语言。在页的@Page指令中或者配置文件的元素中设置(另外该元素内还可以设置属性requestEncoding,responseEncoding,fileEncoding)。Culture="en-us"和Culture="auten-us"的区别在于,后者会先自动匹配,无法自动匹配则用en-us


2、HTTP 允许浏览器使用“接受语言”(Accept-Language) HTTP 请求标头字段将一个首选语言列表发送到 Web 服务器。在IE中选择工具 - Internet 选项 - 语言


3、web.sitemap应用本地化的时候设置的属性enableLocalization="true"。访问全局资源:Resources: 全局资源名, 资源内的key, 默认值;或者resourceKey="web.sitemap.resx文件中的key"


4、编程方式处理用GetGlobalResourceObject() 和 GetLocalResourceObject()


5、编程设置Culture 和 UICulture请重写InitializeCulture(),对 Thread.CurrentThread.CurrentCulture 和 Thread.CurrentThread.CurrentUICulture进行设置


6、访问全局资源: Resources:全局资源名,资源内的key;显式访问本地资源: Resources:key.属性;隐式访问本地资源:meta:resourcekey="key"。



示例
本地化测试
Localization/Test.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Localization_Test" Title="本地化测试" Culture="en-us" UICulture="en-us"
meta:resourcekey="Title" %>




目前语言:



当前时间:
<%=DateTime.Now %>



隐式:



显式:



全局:



编码方式(全局资源):



编码方式(本地资源):



Localize控件方式(Label控件到客户端会解析成&lt;span&gt;,而Localize到客户端后就是解析成其所包含的文字):



中文
&nbsp;
英文



注:

Culture - 决定各种数据类型是如何组织,如数字与日期

UICulture - 决定了采用哪一种本地化资源,也就是使用哪种语言



Localization/Test.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class Localization_Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 以下一看就懂
lbl4.Text = Resources.MyGlobal.GlobalText;
// lbl4.Text = (string)GetGlobalResourceObject("MyGlobal", "GlobalText");


lbl5.Text = (string)GetLocalResourceObject("lbl.Text");


lblCurrentCulture.Text = System.Globalization.CultureInfo.CurrentCulture.Name;
}


protected override void InitializeCulture()
{
// 获取当前Culture的值
string s = Request.QueryString["currentculture"];
if (!String.IsNullOrEmpty(s))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(s);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(s);
}
}


}


从资源文件读图片
Localization/Image.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class Localization_Image : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 一看就懂
System.Drawing.Bitmap img = (System.Drawing.Bitmap)GetGlobalResourceObject(
"MyGlobal",
System.Globalization.CultureInfo.CurrentCulture.Name.ToLower().Replace("-", "_")
);


System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);


Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(ms.ToArray());


img.Dispose();
ms.Dispose();
ms.Flush();
}
}


Web.sitemap本地化摘要







资源文件的内容见源码

[源码下载]


作者:webabcd







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.