可能重复:
CurrentThread.CurrentUICulture is set correctly but seems to be ignored by asp.net
我在很多论坛上都问过,但似乎没有人能够帮助我!
的Default.aspx:
<asp:Literal ID="Literal1" Text="<%$Resources:lookingfor %>" runat="server"/>
default.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
global.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
中的值所以资源经理忽略了文化,而Literal正在使用CORRECT文化!
我在这里缺少什么?
答案 0 :(得分:0)
为什么不将字符串文件全部放在同一个文件夹中。我不知道您的设置是什么,但默认情况下我认为ResourceManager尝试在同一文件夹中查找资源,如果找不到合适的资源,则回退到默认情况下,在您的情况下是strings.txt。