简体   繁体   中英

Globalization with MVC

I am trying to localize my web page, and have done the following :

Added resource files with some example strings

Added a call to a method to set culture and ui culture on the click event of flag icons :

public void SetCulture(string culture)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
    }

And I have made reference to my resource file strings in my web page :

@Resources.General.String1

I have stepped through my code and the culture is successfully changed in my SetCulture method, but the string does not change on the web page. Can anybody advise why?

I don't understand what you mean with the click event in a ASP.NET MVC application. I would use routing to set the new language. A sample you can find at Localization with ASP.NET MVC using Routing .

Instead of using a Javascript event, you have to reload the whole page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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