What are some of the best practices for localizing a lookup table. For example, I created a table called "CompensationType" with the following columns:
Thanks FightAsABull, your solution actually solved the many to many issue, but I have decided to go the RESX file way. In case anyone else is interested, I am posting my solution below.
I am creating a DNN module. DNN breaks away from ASP.NET localization and does its own thing so the code below may seem a little weird in some spots.
The basic idea is to encapsulate the drop down logic in a web user control. The control contains:
Entity Data Source for the lookup table
Make public properties to give access the selected value of drop down list so can bind to it
Use a public property to create an Empty value if needed
It has its own RESX file and other controls can use the definitions too, that way it is all in one place... I couldn't get global resources going in DNN & just want something that works for now.
Here is how the web user control gets used in a details view:
Here is the code behind from the web user control:
Imports System.IO
Imports DotNetNuke
Public Class CompType
Inherits UserControlBase
#Region "PUBLIC PROPERTIES"
Public Property SelectedValue As String
Get
Return ddlCompType.SelectedValue
End Get
Set(value As String)
ddlCompType.SelectedValue = value
End Set
End Property
Public Property AddAnyTypeItem As Boolean
Get
Return ddlCompType.AppendDataBoundItems
End Get
Set(value As Boolean)
ddlCompType.AppendDataBoundItems = value
If value Then
Dim objListItem As New ListItem
objListItem.Text = "ANY TYPE"
objListItem.Value = ""
ddlCompType.Items.Add(objListItem)
End If
End Set
End Property
Private _localResourceFile As String
Public ReadOnly Property LocalResourceFile() As String
Get
If _localResourceFile = String.Empty Then
_localResourceFile = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/" & Path.GetFileName(Me.AppRelativeVirtualPath)
End If
Return _localResourceFile
End Get
End Property
#End Region
#Region "Event Handlers"
Private Sub ddlCompType_DataBound(sender As Object, e As System.EventArgs) Handles ddlCompType.DataBound
'Localize
For Each objListItem As ListItem In ddlCompType.Items
objListItem.Text = Localization.GetString(objListItem.Text, Me.LocalResourceFile)
Next
End Sub
deusbelli
Member
1 Points
19 Posts
Localizing Lookup Tables
Apr 03, 2012 11:40 AM|LINK
What are some of the best practices for localizing a lookup table. For example, I created a table called "CompensationType" with the following columns:
Example row: 2 | 2 | Commission | en-US
Is there a better approach than this?
FightAsABull
Contributor
2228 Points
424 Posts
Re: Localizing Lookup Tables
Apr 05, 2012 06:02 AM|LINK
Hi, this is fine, or you can seperate them into two tables:
•RowID - int
•Code - int
•RowID - int (foreign key)
•LocalizedName - nvarchar(50)
•CultureCode - nvarchar(50)
deusbelli
Member
1 Points
19 Posts
Re: Localizing Lookup Tables
Apr 08, 2012 05:37 AM|LINK
Thanks FightAsABull, your solution actually solved the many to many issue, but I have decided to go the RESX file way. In case anyone else is interested, I am posting my solution below.
I am creating a DNN module. DNN breaks away from ASP.NET localization and does its own thing so the code below may seem a little weird in some spots.
The basic idea is to encapsulate the drop down logic in a web user control. The control contains:
Here is how the web user control gets used in a details view:
<asp:TemplateField SortExpression="CompensationTypeID">
<%---------------------------------------%>
<%-- COMPENSATION TYPE COMBO BOXES --%>
<%---------------------------------------%>
<EditItemTemplate>
<asp:Label ID="lblCompensationType" runat="server" CssClass="label" resourceKey="lblCompensationType" />
<uc1:CompType ID="CompType1" runat="server" SelectedValue='<%# Bind("CompensationTypeID") %>' />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="lblCompensationType" runat="server" CssClass="label" resourceKey="lblCompensationType" />
<uc1:CompType ID="CompType1" runat="server" SelectedValue='<%# Bind("CompensationTypeID") %>' />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCompensationType" runat="server" CssClass="label" resourceKey="lblCompensationType" />
<asp:Label ID="lblCompensationTypeData" runat="server" Text='<%# Eval("ITM_CompensationType.Name") %>' />
</ItemTemplate>
</asp:TemplateField>
Here is how the web user control gets used in a filter control:
<uc1:CompType ID="ddlCompensationType" runat="server" AddAnyTypeItem="true" />
Here is the code behind from the web user control:
Imports System.IO
Imports DotNetNuke
Public Class CompType
Inherits UserControlBase
#Region "PUBLIC PROPERTIES"
Public Property SelectedValue As String
Get
Return ddlCompType.SelectedValue
End Get
Set(value As String)
ddlCompType.SelectedValue = value
End Set
End Property
Public Property AddAnyTypeItem As Boolean
Get
Return ddlCompType.AppendDataBoundItems
End Get
Set(value As Boolean)
ddlCompType.AppendDataBoundItems = value
If value Then
Dim objListItem As New ListItem
objListItem.Text = "ANY TYPE"
objListItem.Value = ""
ddlCompType.Items.Add(objListItem)
End If
End Set
End Property
Private _localResourceFile As String
Public ReadOnly Property LocalResourceFile() As String
Get
If _localResourceFile = String.Empty Then
_localResourceFile = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/" & Path.GetFileName(Me.AppRelativeVirtualPath)
End If
Return _localResourceFile
End Get
End Property
#End Region
#Region "Event Handlers"
Private Sub ddlCompType_DataBound(sender As Object, e As System.EventArgs) Handles ddlCompType.DataBound
'Localize
For Each objListItem As ListItem In ddlCompType.Items
objListItem.Text = Localization.GetString(objListItem.Text, Me.LocalResourceFile)
Next
End Sub
#End Region
End Class