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: