One of my programming friends (who is considering to switch from VB6 to RS) asked me to put some tips/snippets, on my blog. So here we go… This example shows how to build a multilangual ConfirmDelete dialog.
When you are developing commercial software it is important (from sales perspective) to support as many languages as possible. Here comes in one of the great strengths of Real Studio: RS has native multilanguage capabilities. The language used in the application will be the language that the user is running on his computer, if it is supported by the application. Otherwise the appliciation will switch to the default language of the application:
In this case the default language for the application is English. To add multi language capabilities to our application we have to add a module:
‘Module1’ will be created, let’s change the name of the module to ‘ml’ so we know this module is used for the languages:
As you may probably already know, texts in labels and forms in an application are defined as ‘Captions’. We wish to ‘fill’ the captions in our application from a text contant. In our module we have the possibility to add those text constants. First double click on our ‘ml’ module to be able to work with it, your screen should look like this after opening the module:
Notice that a new tab ‘ml’ is opened and active. Now click on ‘Add Consant’ (right below the ml tab)
- Constant Name: AreYouSureDelete
- Default Value: Are you sure to delete
- Type: choose for string, notice that after this choise a checkbox ‘Dynamic’ shows up
- Check the box ‘Dynamic’
Your screen should look like this:
The checkbox ‘Dynamic’ is very important, it is responsible for dynamicly switching to the right language and giving the appropriate text to the application. In this case I have made the constant protected with the yellow triangle (see below).
With the + sign below the constant we are able to enter different values, per platform and per language. Right now we fill out English and Dutch as below example:
In above example I have already added all constants that we need. Now we need a piece of code to call a dialog and to use our newly created constants, you may paste (or create manually) this function in the form:
Private Function ConfirmDelete(Section as String) As Boolean 'Display a dialog that asks the user to confirm their delete action. 'The dialog returns true if the delete has been confirmed. Dim dlog As MessageDialog 'Create the Dialog dlog = New MessageDialog dlog.Message = ml.AreYouSureDelete + lowercase(section) + ml.AreYouSureDelete2 + "?" dlog.Explanation = ml.ActionCannotUndo dlog.ActionButton.Caption = ml.Delete dlog.CancelButton.Caption = ml.Cancel dlog.CancelButton.Visible = True 'Show the Dialog 'Return True if Confirmed If dlog.ShowModal.Caption = ml.Delete Then Return True End If 'Cancel the delete Return False End Function
To call the function I have put a button on my form. This button is, for instance, to delete a record from a database:
I gave this button the name ‘pbDelete’. This button should also be translated. Best way to do this is to translate the caption when opening the form in the form ‘Open’ event. To access this event quickly, double click in the form and add the code for the translation as below:
Now go back to your form (click on tab Window1) and doubleclick on the button to open it’s action event and add the the for the action as below:
Now click on Run to check the result, the application should appear like this (if you are from the Netherlands):
Click on the button, following dialog should appear:
As you can see we haven’t translated everything in our application. I leave that to your own imagination. I hope this explantion has been useful to you!
Please find the example project here: RS Multilanguage Example