Can I NOT using culture-neutral resource file? RRS feed

  • Question

  • User-1633640756 posted


    I am using .NET 2.0

    I set culture in code-behind, regardless the Browser language settings.


    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

     Dim lang As String = CStr(IIf(CStr(Session("Lang")).ToLower = "french", "fr-CA", "en-CA"))

     Dim ci As New System.Globalization.CultureInfo(lang)

     System.Threading.Thread.CurrentThread.CurrentCulture = ci

     System.Threading.Thread.CurrentThread.CurrentUICulture = ci

    End Sub

    So under \App_LocalResources, I added two culture-specific file:




    so here is I want to display a lable text:

    <asp:Label ID="lblTitle" runat="server" Text="<%$ Resources:lblTitle.Text %>" ></asp:Label>

    when I compiles it give me error: The resource object with key 'lblTitle.Text' was not found.


    However, if I create a culture-neutral resource file like this: Help.aspx.resx

    Everything works fine!

    my question, why I need this culture-neutral file, giving that all keys in that file are empty, seems have no use at all
    I even specified in Web.Config to default the language to 'en-CA' like this:

    <globalization uiCulture="auto:en" culture="auto:en-CA" />

    still doesn't work as long as that Help.aspx.resx is not there.

    Can somebody help me on this?

    Thank you

    Saturday, September 9, 2006 12:04 AM

All replies

  • User83354550 posted


    You are very nearly there, the reason it is not finding lbTitle.text is because you are setting your UI culture to ci.

    Common practice is to have a default resource file like your one taht works with no language string within it, and then a resource file for each of the languages you wish to support. Make sure you put the full language setting text i.e. "fr-CA" or "en-CA" (exactly how you spelt it in the resource file names) and not just nuetrol setting for a language like "ci". Also, you should catch errors when setting a threads culture and then set the language to "", this will then force the app to load the standard resource file rather then throw an unhandled error.

    Hope this helps, please let me know.


    Thursday, February 8, 2007 8:58 AM