Help with Multi-language site

Discussion in 'ASP .Net' started by marcus, Dec 7, 2004.

  1. marcus

    marcus Guest

    I am developing a web site at work that needs to be both in French and
    English. I have been reading up on using resource files (.resx files) in
    combination with setting the CultureInfo to either "en-CA" (Canadian
    English) or "fr" (French), then retrieving the appropriate variables from
    the resx file with a ResourceManager depending on the current Culture. That
    seems straightforwrad enough. Whenever I want a label or any other control
    that displays text to display text, I just assign its text value the value
    in the resx file. What I would like to do is encapsulate that whole process
    so all I need to do is call a sub, for example "setPageText", in an object,
    for example "Language", that would do all the labelling of the controls for
    me. I thought that maybe I could just have the sub take as a parameter the
    entire page. It could then loop through all the controls and set the text
    property of each to the right value that is pulled from the resx file. So
    the way I see it, all I would have to do in the Page_Load is include this

    Dim myLanguage as new Language("myResourceFileName")

    The code below seems to do the trick for looping through the controls of the
    page (it actually seems to loop more times that I would have expected
    showing "literal controls" -- does it consider straight html as a literal
    control?). However, how can I set the text value of each of the controls if
    I don't know what kind of control it is? Basically, any control that has a
    text value (label, checkbox, radio button, etc) I would like to set its
    value using the resx file. I am moreorless new to ASP.Net and VB.Net, so
    perhaps this is an easy question. I guess once I find out what kind of
    control it is, I would then cast it to this conrol and then set its text
    value? Or is no casting necessary?

    Is there some soundness in the general idea of what I am trying to
    accomplish, or is there another way that I should be considering? In a
    nutshell, I don't want to have to call the ResourceManger's getString()
    function everytime I have text that could be in either English or French.

    Thanks for any suggestions,
    Marcus Bell

    Public Class Language
    Protected myRM As ResourceManager

    Sub New(ByVal myResource As String)
    myRM = New ResourceManager(myResource, GetType(junk3).Assembly)
    End Sub

    Sub setPageText(ByVal myControl As Control)
    Dim myType As String
    Dim name As String
    Dim c As Control
    If myControl.HasControls Then
    For Each c In myControl.Controls
    myType = myControl.GetType.ToString
    name = myControl.ID
    If name <> "" Then
    '****** put code here that determines the type of control
    that is currently in scope and get the text from the resrouce file
    '****** using the ResourceManger class
    End If
    End If
    End Sub
    End Class
    marcus, Dec 7, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Seguin

    Multi-language web site

    Karl Seguin, Feb 17, 2005, in forum: ASP .Net
    Feb 17, 2005
  2. Aussie Rules

    multi language site...

    Aussie Rules, Oct 5, 2007, in forum: ASP .Net
    Steven Cheng[MSFT]
    Oct 9, 2007
  3. Mike Gleason jr Couturier

    Multi-language site and physical hierarchy

    Mike Gleason jr Couturier, Mar 28, 2008, in forum: ASP .Net
    Mike Gleason jr Couturier
    Mar 28, 2008
  4. Martin P. Hellwig
    John Ladasky
    Oct 17, 2011
  5. prschmid

    Multi Language Site

    prschmid, Jul 25, 2004, in forum: ASP General
    Jul 27, 2004

Share This Page