开发者

resourcemanager uses wrong UICulture to serve content! Always returns neutral culture [duplicate]

开发者 https://www.devze.com 2023-03-02 13:45 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: CurrentThread.CurrentUICulture is set correctly but seems to be ignored by asp.net
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

CurrentThread.CurrentUICulture is set correctly but seems to be ignored by asp.net

I've asked on many forums, but no one seems to be able to help me!

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 current开发者_运维百科culture:
            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 folder: In my bin folder I have:

bin\strings.txt
bin\nl\strings.nl.txt
bin\en\strings.en.txt

I generate the dlls like so:

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  

Now when I load default.aspx

The Literal1 control shows: 'What are you looking for?' this is the value from App_LocalResources\default.aspx.en.resx, so that is correct.

But the Page Title (Me.Page.Title = rm.GetString("homewelcome")) shows the value from bin\strings.txt! That is ofcourse incorrect as I would want it to show the value from bin\en\strings.txt

So the resource manager is ignoring the culture, whereas the Literal is using the CORRECT culture!

What am I missing here?


Why don't you put the strings files all in the same folder. I don't know what are your setup but by default I think the ResourceManager try to look for resource in the same folder and if it doesn't find a appropriate one fall back to the default one which in your case is strings.txt.

resourcemanager uses wrong UICulture to serve content! Always returns neutral culture [duplicate]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号