how to make multilingual site in asp.net

2019-05-06 23:27发布

问题:

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. 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. How we can do this? or how we can choose a particular language resource file???

回答1:

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(); 
}


回答2:

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



回答3:

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!



回答4:

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...