惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 小新0574

PayPal使用介绍 - 注册篇 VB6.0 IDE即将退出历史舞台 工作一年半记录 随便说说Silverlight 最近在学英语 真正理解ViewState - Part2 真正理解ViewState - part1 本地模式使用ReportViewer控件 ADO.NET2.0跟ADO.NET3.0的一些新特性简要介绍 关于Membership的设置 本地生成RDL报表文件的创建工具 使用WebService动态生成DataSet绑定到Reporting Services 可爱的上海人 Just a Test 回到了学校 到了上海 打算近期去深圳找工作 ASP.NET中的事件 第一天学习《Essential ASP.NET...》情况
编程使用资源文件实现多语言页面(In Action)
小新0574 · 2006-09-07 · via 博客园 - 小新0574

需求:我们的ASP.NET站点需要提供多语言支持,考虑到我们使用的是ASP.NET2.0,我们可以利用资源文件来实现。

NOTE:这里我们使用编程的方法实现,使用其他方法,请参见:

http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

接下来我们演示一个简单的例子

Steps:

Step1:Visual Studio2005中创建一个ASP.NET站点

Step2:在网站项目中添加App_GlobalResources

Note:这里我们使用全局资源文件作为演示,本地资源文件操作步骤类似,关于全局资源文件与本地资源文件的异同,请参见

http://msdn2.microsoft.com/en-us/library/ms227427.aspx

Choosing Between Global and Local Resource Files这一段

Step3:App_GlobalResources中添加项,选择Resource File模板,取名为Site.resx

Note:这是我们的默认语言资源文件,必须要有

在这个资源文件的键/值配对中写入:

Name : btnSubmitText

Value: Submit

Step4:增加我们需要的各种语言的资源文件,这里我们增加两个文件

Site.zh-CN.resx

在这个资源文件的键/值配对中写入:

Name : btnSubmitText

Value: 确定

Site.en-US.resx

在这个资源文件的键/值配对中写入:

Name : btnSubmitText

Value: Submit

Note:这里给资源文件取名的时候,需要按照如下格式:

[Class]. [Culture Name].resx

比如说Site.zh-CN.resx

关于Culture Name请参见MSDNCultureInfo类中的Remarks部分

Step5:在我们的Default页面中添加一个Button控件,IDbtnSubmit

Step6:在我们的Default页面中添加两个Button控件,IDbtnChinese,btnEnglish,Text为中文,English

btnChineseClick事件方法中,添加代码:

        Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
        btnSubmit.Text 
= Resources.Site.btnSubmitText;

btnEnglishClick事件方法中,添加代码:

        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        btnSubmit.Text 
= Resources.Site.btnSubmitText;

Note:如果我们不在代码里指定当前线程的CurrentUICulture,那么程序就会根据浏览器中的设置进行判断,你可以在IE中的语言设置中进行默认设置。

OK, 我们可以运行了。

UAT就让大家来做吧,呵呵。不出所料,一切都如我们所预料的运行。

By the way, 最近发的几篇文章难度都不是很高,其实重要的是告诉大家一种可以选择的方法,或是大家都不是很注意的一些知识点, 引导大家如果有需要继续去发掘,MSDN里有的内容,我就简要介绍或者直接给出链接,那样就不会显得文章庞大臃肿,让大家集中注意力在某一些点上。Enjoy it J

PS:欢迎大家加我的MSN或者QQ讨论.NET 2.0(主要是C#2.0ASP.NET2.0).NET3.0,发现我加入的几个QQ群都还挺少有人讨论这两个版本的内容的。还有一些朋友问我的很多问题,其实通过查找MSDN都可以找到答案跟示例,所以我的建议是,首先通过自己查找资料寻找解决方案。还有一些朋友直接向我要源码,或者说让我做一个MSDN示例里已经有代码的演示Project,那我的建议是,你还是自己先去尝试着做吧,我做好给你,你再看肯定没有你自己做一边效果来的好。