From http://www.cnblogs.com/think8848/archive/2011/03/19/1988690.html
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:
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 { |
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:
From http://www.cnblogs.com/think8848/archive/2011/03/19/1988690.html
In the last two articles (1, 2), I mentioned how to use resource files in application projects. I have not tested how to call other Chinese source files in classlibrary, this morning, according to ASP. net project practices for a test
Use resource files:
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 { |
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 code is added to its method:
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: