[Original] ASP. net mvc 3 razor multi-language reference solution Supplement 2

Source: Internet
Author: User

In the last two articles (1, 2), I mentioned how to applyProgramThe resource file usage problem in the project has not been tested in the case of calling other classlibrary Chinese source files. This morning, we also conducted a test in accordance with the previous ASP. NET project practices.

Use resource files:

 
Public class class1 {Public String gettt () {return resources. Test. tt ;}}

It is expected that, as the language options in the browser change, the system will automatically switch, and the results will not be unexpected, but only the resource item values with no culture information will be displayed.

(Important updates in March 22: added to the system. Web configuration node of Web. config<Globalization culture = "Auto" uiculture = "Auto"/>You don't need to use the following methods !!!)

By checking the designer. CS file of the resource file, it is found that there is an internal attribute definition:

[Global: system. componentmodel. editorbrowsableattribute (Global: system. componentmodel. editorbrowsablestate. advanced)] internal static Global: system. globalization. cultureinfo culture {get {return resourceculture;} set {resourceculture = value ;}}

So I guess that if this attribute value can be set, I must have ResourceManager automatically select the corresponding resource file. But where can it be added? I found that there is such an event in httpapplication:

 
Public event eventhandler prerequesthandlerexecute;

Therefore, the event processor of this event is added to global, and the following is added to its method:Code:

Protected void application_prerequesthandlerexecute (Object sender, eventargs e) {thread. currentthread. currentculture = cultureinfo. getcultureinfo (request. userages [0]); thread. currentthread. currentuiculture = thread. currentthread. currentculture ;}

F5 runs, which achieves the expected results: with the browser language option switching, the language on the page can also be automatically switched.

English:

Chinese:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.