The .NET Framework has great support for multi-language applications. You can put all your translated form text in resource files. What happens when you bind a
DataSet to a grid? In our case, we use Component One's
TrueDBGrid. If you make a form localizable, all the formatting of the grid becomes language-dependent. It would be great to make only the columns' captions language-dependent. Then, the next problem arises: you have to maintain all the forms. It would make more sense to put the translations of the data fields' captions in the
DataSet definition itself. And that's what I have made, using an adapted version of Shawn Wildermuth's DataSet Generator.
First, read my previous article on Inherited DataSets. The version of the DataSet Generator with this article is basically a further developed version.
The magic is done with this piece of generated code:
Public Overridable Property Localizable() As Boolean
Set(ByVal Value As Boolean)
_Localizable = value
If value Then
Dim resourceManager As System.Resources.ResourceManager = New
Dim tableIndex As Integer
Dim columnIndex As Integer
Dim caption As String
tableIndex = 0
Do While (tableIndex < Me.Tables.Count)
columnIndex = 0
Do While (columnIndex < Me.Tables(tableIndex).Columns.Count)
caption = resourceManager.GetString( _
String.Join(".", New String()_
Catch ex As System.Exception
If (Not (caption) Is Nothing) Then
Me.Tables(tableIndex).Columns(columnIndex).Caption = caption
columnIndex = (columnIndex + 1)
tableIndex = (tableIndex + 1)
All you have to do to make the
Caption property language dependent, is put the translations in .resx files with the same name as the
DataSet's generated code file. If your
DataSet's XSD is called DataSet1.xsd, the generated code file will be called DataSet1.vb (if you're working on a VB.NET project). The files you have to add to your project must be named DataSet1.vb.resx, DataSet1.vb.nl.resx, etc. To give you a good start, I put a little routine in the test project that creates these files for you and fills it with all the columns' captions. Just press the button on the correct form.
The choice is yours!
Of course, you don't want to translate all captions all the time. Accessing resource files may create unnecessary overhead. First, if you leave out Caption translations from the resource files, no translation work will be done. Second, as long as you don't set the
Localizable property to
True (e.g. from the Form Designer in Visual Studio), no translation work is done at all.
Wout de Zeeuw proposed translating object properties so they would display correctly in a
PropertyGrid. I spent some time trying to port this Attribute centered approach to the
DataSet, but it gave me too many headaches. If you want to use the .NET
PropertyGrid, my solution may not be the best one.
My first encounters with computers where Sinclair, TI99-4A, C64, Apple II. Have programmed ever since. Worked for a few logistic companies.
I have been a VB.NET programmer for quite some years. I work with a small firm, that specializes in supply chain planning for bulk products. We have our own application, Delivery+, that helps vehicle planners with their daily job.
I am married and I have two children. I am building an eco-friendly house and try to live green.