The Translation Table Manager
shows the Translation Table Manager form in the Designer. I include this in my applications so that users can manage their translations themselves (although in most cases, only users with the appropriate rights can see the form). The form inherits from my inheritable form BaseForm, to be described a little later on, so it has a FormPreparer and a DAC component, and is also translatable. This screen initially displays all of the captions that have been harvested from forms in which the StoreCaptions method of the FormPreparer component has been run. Figure 2
shows the form with only the original captions loaded.
Figure 1. Translation Table Manager Form in the Designer.
Figure 2. Translation Table Manager in Action.
In the Translation Table Manager's Load
event, the Original
table is loaded in the left column of the grid; the right column contains the corresponding strings for the currently selected language (based on the Language combo box at the upper left corner of the screen) loaded from the Translations
table. Figure 3
shows the form with the Spanish translations loaded.
Figure 3. Adding Spanish Translations to the Translation Table Manager.
Figure 4. Building BaseForm.vb.
Rather than allow editing in the active row of the grid, I put a pair of textboxes below the form to display the original string and allow the user to enter or edit the translation. Captions can be long, and it's useful to be able to see the entire text of the original language while typing the translation. So the user selects a row, clicks on the "Edit" button, adds or edits the translated text, and clicks Save or Cancel. Delete just deletes the translation, not the original entry, which came from the application's forms and can't be altered by the translator. Listing 3
shows the code for the Translation Manager form.
Using the Translation Tables in Your Windows Forms
|Figure 5: The TranslationDemo Project with MainForm.vb and Customers.vb.|
Now that you know how the text captions are collected and stored, and how translations are created and stored in tables, how do you use them in your forms? Just put the code to translate the form into the inheritable form template classes that all your forms inherit from, and drop a combo box with all available languages on the form. In its SelectedIndexChanged
event code, look up the original captions of controls and MenuItems, retrieve the translation for the current language's translation from the Translated
table, and assign it to the control or MenuItem's Text
I built an inheritable form called BaseForm, shown in Figure 4
. The distinguishing characteristic is the combo box, cmbLanguagePicker
, which I load with the names of the available languages in the Load
event. The code for the combobox's SelectedIndexChanged
event, which translates all control and MenuItem captions on the form, is shown in Listing 4
. The shaded code is an overloaded constructor (New
) method that lets me pass two DAC components to the form when it's created.
I then added two forms that inherit from this base form class: MainForm.vb
, seen in the TranslationDemo project shown in Figure 5
and Figure 7
show the MainForm and a Customers form, respectively. To create them, right-click on the TranslationDemo project, select Add, Inherited form, provide the form name, and select BaseForm as the form from which to inherit.
On the Customers form, I added three labels and three textboxes corresponding to three of the columns in the Customers table of the Northwind database. The Tables, Customers pad of the MainMenu control in MainForm contains four lines of code to instantiate the customers form, pass in the references to the two DAC objects, and activate the form:
Dim frm As New Customers
frm.AppDataDAC = AppDataDAC
frm.TranslatorDAC = TranslatorDAC