Sat*_*ngh 6 .net c# asp.net localization
我使用(Asp.net,c#)建立了一个网站,其内容是英文的.现在我要求以支持多种语言的方式建立这个网站,即(德语,法语).Lable/Textbox/string所有值将显示各自选定的语言在搜索时我发现有一些方法
坦率地说,我不同意第三种选择.
我想知道哪种方式最好或者还有其他更好的方法吗?
注意:当前网站是使用.NET framework 4.0/vs 2010构建的.
谢谢
小智 5
Resx:
http://msdn.microsoft.com/en-us/library/ms227427.aspx
http://dreamdotnet.blogspot.com/2007/01/tutorial-translating-aspnet-web.html
您可以将resx文件用于多种语言,并使用ResXResourceWrite对其进行更新(如果希望用户能够更新文件,请访问:http : //msdn.microsoft.com/zh-cn/library/system.resources。 resxresourcewriter.aspx)
如果您希望能够翻译数据库中的内容(例如,如果您的数据库中存储了产品,并且您希望产品的描述也将是多语言的),则此解决方案仅对静态内容有用。在这种情况下,您需要更改数据库架构,以支持多语言内容。
您可以使用PS GetLocalResourceObject("key")来检索值,而无需使用Web控件。
如果您使用的是MVC,请参见以下问题:如何本地化ASP.NET MVC应用程序?
我使用资源文件添加 global.asax 完成的示例代码
void Application_BeginRequest(Object sender, EventArgs e)
{
// Code that runs on application startup
HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28644 次 |
| 最近记录: |