By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

Help with Multi-language site

P: n/a
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
Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.