我在很多论坛上问过,但似乎没有人能帮助我!
默认.aspx:
<asp:Literal ID="Literal1" Text="<%$Resources:lookingfor %>" runat="server"/>
默认.aspx.vb:
Shared rm As ResourceManager = HttpContext.Current.Application("RM")
Protected Overrides Sub InitializeCulture()
Dim cultureInfo As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("en")
Threading.Thread.CurrentThread.CurrentCulture = cultureInfo
Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo
'Here I log the value of currentculture
ReportError("default.aspx:InitializeCulture.CurrentCulture", System.Threading.Thread.CurrentThread.CurrentCulture.ToString)
ReportError("default.aspx:InitializeCulture.CurrentUICulture", System.Threading.Thread.CurrentThread.CurrentUICulture.ToString)
'log file shows that:
'CurrentCulture = "en-US"
'CurrentUICulture= "en-US"
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'again logging the currentculture:
ReportError("default.aspx:page_load.CurrentCulture", System.Threading.Thread.CurrentThread.CurrentCulture.ToString)
ReportError("default.aspx:page_load.CurrentUICulture", System.Threading.Thread.CurrentThread.CurrentUICulture.ToString)
'log file shows that:
'CurrentCulture = "en-US"
'CurrentUICulture= "en-US"
Me.Page.Title = rm.GetString("homewelcome")
End If
End Sub
全球.asax:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("RM") = New ResourceManager("strings", Assembly.Load("strings"))
End Sub
\bin 文件夹:在我的 bin 文件夹中,我有:
bin\strings.txt bin\nl\strings.nl.txt bin\en\strings.en.txt
我像这样生成dll:
resgen strings.txt strings.resources al /embed:strings.resources,strings.resources /out:strings.dll resgen nl\strings.nl.resources al /embed:nl\strings.nl.resources,strings.nl.resources /out:nl\strings.resources.dll /c:nl resgen en\strings.en.resources al /embed:en\strings.en.resources,strings.en.resources /out:en\strings.resources.dll /c:en
现在当我加载 default.aspx
Literal1 控件显示:“您在寻找什么?” 这是来自 App_LocalResources\default.aspx.en.resx 的值,所以这是正确的。
但是页面标题 (Me.Page.Title = rm.GetString("homewelcome")) 显示来自 bin\strings.txt 的值!这当然是不正确的,因为我希望它显示 bin\en\strings.txt 中的值
所以资源管理器忽略了文化,而文字使用的是正确的文化!
我在这里想念什么?