I have been toying with an idea that would not affect the DNN Core, would work with any ASP.Net site (not just DNN) to dynamically inject a translation into a controls presentation layer (text, value, items, etc). The following is some psuedo code/table design for example purposes, but I believe the concept could work. I do have some of it built and it works fine (the Find Control stuff works great), but need some advice...
Database Table Design:
fld_Value = NTEXT (the field datatype)
fld_Id |
fld_Language |
fld_Control_Id |
fld_Value |
1 |
en-CA |
lbl_Message |
Hello |
2 |
fr-CA |
lbl_Message |
Bonjour |
3 |
fr-GE |
lbl_Message |
Hallo |
User navigates to the site. They change the Language choice or a value stored in a cookie remembers the language preference. Code in the module determines if a Site Wide Array is available. This array is filled with values required to populate controls on the Portal for the selected language. If the Site Wide Array does not exist, then it is created on the fly based on the language of choice. The values in the array are populated with values in a database table, similar to the design shown above.
Question? Is it possible to store values from a database table to an Array that is available Site wide? Or is there some other method we could use to hold values that are available on the site but accessible to any asp.net web page/dnn module. Thought...I think it would be better to store the different languages in there own array and have them available when called upon from code to update a control presentation property.
So if we are able to create a Site Wide Array then in the DNN module we access a function in the Page_Load or Page_Init event.
The function loops through all controls on the page. In a Select Case we take the Control_Id and filter the array for the value. For example if the user has selected French Canadian we inspect the fr-CA array. We then isolate the value(s) for the Control_Id found in the Find Control Function. In the Select Case we pass the value in the Array to the Control_Id presentation property.
For example if we have a label and the control_id is lbl_Message, and the language of choice is fr-CA then the return value from the Array is Bonjour. The text property of the control is set to "Bonjour".
If the control on the page is a drop down list then a function clears the list and passes the values from the array to the drop down list (So in the table we would have for example 5 records with the same Control_Id and fld_Language.
All we need is one or more functions to handle the various ASP.Net controls. I haven't put much thought into handling a GridView or DataGrid at the moment, but the Site Wide Array is the tricky part.
Thoughts on the Idea? Site Wide Array? Can it be done?
Thanks,
eformx - www.soccermanager.ca
Ps. The Find Control code...
Private
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If Not Page.IsPostBack Then
'Use the following to call the private procedure from the Page_Load
LoopControls(Page)
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(
Me, exc)
End Try
End Sub
'the private procedure
Private
Sub LoopControls(ByVal parent As Control)
Dim c As Control
For Each c In parent.Controls
If c.GetType() Is GetType(TextBox) Then
'Do something with the TextBox
DirectCast(c, TextBox).Text = "Hi eformx"
'pass control id to stored procedure or array to get language for control
Dim strMy As String = c.ID
End If
If c.HasControls Then
LoopControls(c)
End If
Next
End Sub