本地化asp.net网站与一个全球资源构成 [英] localization in asp.net web forms with one global resource
问题描述
我想有一个一些资源文件是这样的:
Mui.resx
Mui.fr.resx
Mui.es.resx
...
和我希望能够在我的codebehind是这样做的:
Label1.Text = Mui.Hello;
在我的aspx是这样的:
<%= Mui.Hello%GT;
有人知道如何做到这一点?这可能吗?
是的,它是可能的。您可以从文件 - 新建 - 资源添加资源文件文件
有你想要的英文或其他语言,您可以添加自己的资源键和值,
检查这些
如何:检索资源价值编程并的 ASP.NET网页资源概述
要检索使用强类型的全球资源
块引用>
- 使用下面的语法获取资源:
Resources.Class.Resource
示例:
块引用>字符串的欢迎;
欢迎= Resources.WebResources.WelcomeText;
但是,如果你使用本地化
你有没有检查这个MSDN种源:结果
演练:使用资源本地化用ASP.NET
块引用>检查上面的链接部分
明确本地化与ASP.NET
。示例:
标签的文本属性现在有一个明确的前pression说明从中检索资源,并选择关键基础文件。
< ASP:标签ID =Label2的=服务器文本=<%$资源:LocalizedText,MSG 1%GT;>
和您的网页上:
简单的调用与资源键的完整路径。检查这篇大文章 - 资源,本土化这将解释更多关于这一点。
编辑 - Web.Config中文化设置:结果
添加此结果<全球化文化=自动的UICulture =自动enableClientBasedCulture =真/>
在web.config中在<的System.Web&GT ;
如果你想让它在一些网页上,然后使用
< @页>
指令的文化
和的UICulture
属性。I want to have one some resource files like this:
Mui.resx Mui.fr.resx Mui.es.resx ...
and I want to be able to do in my codebehind something like this:
Label1.Text = Mui.Hello;
and in my aspx something like this:
<%=Mui.Hello %>
anybody knows how to do this ? is it possible ?
解决方案Yes it is possible. You can add your resource file from
File-New- Resource File
and there you can add their own Resource key and their values as you want either in English or other language.,Check these How to: Retrieve Resource Values Programmatically and ASP.NET Web Page Resources Overview
To retrieve global resources using strong typing
Example:
- Get the resource using the following syntax:
Resources.Class.Resource
String welcome; welcome = Resources.WebResources.WelcomeText;
But if you using Localization Have you check this MSDN resouce:
Walkthrough: Using Resources for Localization with ASP.NETCheck the section
Explicit Localization with ASP.NET
on the link above.Example:
label's text attribute now has an explicit expression stating the base file from which to retrieve the resource and the key to select.
<asp:Label ID="Label2" Runat="server" Text="<%$ Resources:LocalizedText, Msg1 %>">
And on your page: Simple call with full path of resource key.
Check this great article - Resources and Localization that will explain you more about this.
Edit- Web.Config Culture Settings:
Add this
<globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
in web.config under<system.web>
If you want it on some pages then use
<@Page>
directive'sCulture
andUICulture
attributes.这篇关于本地化asp.net网站与一个全球资源构成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!