Help with Multi-language site

M

marcus

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
code:

Dim myLanguage as new Language("myResourceFileName")
myLanguage.setPageText(me)

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
setPageText(c)
Next
Else
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
*****************************************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top