简体   繁体   English

如何在 asp.net 中制作多语言网站

[英]how to make multilingual site in asp.net

I am developing a site in asp.net in multiple languages but i didn't understand how this can be done because we can manage multilingual language by using resource files.我正在用多种语言在 asp.net 中开发一个站点,但我不明白如何做到这一点,因为我们可以通过使用资源文件来管理多语言。 we did this, but my major problem is that how we can change globalization at run time for a particular user.我们这样做了,但我的主要问题是我们如何在运行时为特定用户更改全球化。 if A user choose English language then he/she can view this i English and if B user choose Spanish then he/she can view this site in Spanish.如果 A 用户选择英语,那么他/她可以用英语查看这个网站,如果 B 用户选择西班牙语,那么他/她可以用西班牙语查看这个网站。 How we can do this?我们怎么能做到这一点? or how we can choose a particular language resource file???或者我们如何选择特定的语言资源文件???

use this code使用此代码

protected override void InitializeCulture() 
{ 
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); //'en-US' these values are may be in your session and you  can use those
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");//'en-US' these values are may be in your session and you  can use those
    base.InitializeCulture(); 
}

I had this same question when i started developing multilingual sites and i found those two articles as the best starting point:当我开始开发多语言网站时,我也有同样的问题,我发现这两篇文章是最好的起点:

http://www.codeproject.com/KB/aspnet/localization_websites.aspx http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2.aspx http://www.codeproject.com/KB/aspnet/localization_websites.aspx http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2.aspx

you could try something like this:你可以尝试这样的事情:

string culture = "en-US"; //could come from anything (session, database, control, etc..)

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

I think it works!我认为它有效!

you need to use localization for language and individual resource file.您需要对语言和单个资源文件使用本地化。 Now when your site is being access at client side you need to check the locale setting on client's machine his date/time setting and the Default language... on the basis of this you can provide language that user wish...现在,当您的网站在客户端被访问时,您需要检查客户端机器上的语言环境设置,他的日期/时间设置和默认语言...在此基础上,您可以提供用户希望的语言...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM